0

I have a folder structure like so:

/mylib/
/mylib/__init__.py
/mylib/my_class.py
/mylib/tests/test_my_lib.py

In my test, I have:

from mylib import MyClass
import unittest

I'm getting:

  File "test_edgecast_mcc_client.py", line 1, in <module>
    from mylib import MyClass
ImportError: No module named mylib

Which, I think, makes sense because the import would be looking inside the tests directory for mylib when it should be looking in ../mylib?

Can anyone share some light on how to get the import to work properly?

1
  • Is mylib on your Python module search path? Commented Jan 17, 2013 at 1:16

3 Answers 3

1

I believe your tests package needs an __init__.py file too

Sign up to request clarification or add additional context in comments.

Comments

0

Add primary directory to $PYTHONPATH. You can do it from your test_my_lib.py using something like this:

import sys
import os.path

d = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.insert(0, d)

Comments

0

try using this from command line and see if that eliminates the error

export PYTHONPATH="$PYTHONPATH:/path/to/mylib/"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.