0

I have the follwoing package structure

my-base-project
-> package1
    __init__.py
    MyScript.py
-> test
    __init__.py
    TestMyScript.py

I'd like to run the TestMyScript.py in the console. Therefore I cd in to my-base-project/test and execute python TestMyScript.py. However, I'm getting the error:

user@computer:~/my-base-project/test$ python TestMyScript.py 
Traceback (most recent call last):
  File "TestMyScript.py", line 4, in <module>
    from package1 import MyScript
ImportError: No module named package1

How do I run these tests?

toom
  • 11,026
  • 22
  • 77
  • 119

1 Answers1

0

From this SO question, consider adding the directory you need to the PYTHONPATH:

 import sys
 sys.path.append('your certain directory')

Maybe you want to add the parent directory

sys.path.append('..')
Community
  • 1
  • 1
M. K. Hunter
  • 1,622
  • 3
  • 19
  • 27