Reputation: 914
When I print sys.path in my code I get the following as output:
['C:\Netra_Step_2015\Tests\SVTestcases', 'C:\Netra_Step_2015\Tests\SVTestcases\TC-Regression', 'C:\Python27\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', etc.]
Now, when I write "import testCaseBase as TCB" where testcaseBase.py is in this path:
C:\Netra_Step_2015\Tests\SVTestcases\Common\shared
I get an error: "ImportError: No module named testCaseBase"
My code is in C:\Netra_Step_2015\Tests\SVTestcases\TC-Regression\regression.py. My code goes ahead with compilation, but testcaseBase.py which is residing in a parallel directory fails to compile.
What might be the reason?
Upvotes: 0
Views: 15364
Reputation: 31
Please dont use ~/ in the path . it does not work. Use the full path.
Upvotes: 1
Reputation: 2223
put
C:\Netra_Step_2015\Tests\SVTestcases\Common\shared
in your PYTHONPATH env
Upvotes: 2
Reputation: 2491
Perhaps I'm missing something, but this file path...
C:\Netra_Step_2015\Tests\SVTestcases\Common\shared
...isn't in your sys.path
, so it's not surprising you got an error. You have several options though. Changing your project structure or, if Common
and shared
are actual packages with __init__.py
defined inside of them, do:
import Common.shared.testCaseBase
You can also just append the path in your calling script, so:
sys.path.append('\SVTestcases\Common\shared')
Or, actually just add the following path to your ENV variable (PYTHONPATH
)
C:\Netra_Step_2015\Tests\SVTestcases\Common\shared
But it's not necessarily a good habit to substitute good directory structure and importing techniques with editing your PYTHONPATH
each time. You'll be much better off if you resolve this another way.
Upvotes: 4