Reputation: 12224
I wrote some Python programs about 7 or 8 years ago and I haven't touched them since, although they are still in heavy use by my company.
We have moved to a new server, and I'm trying to set that environment up. I have created all of the code, but apparently I have some sort of path problem that I don't remember how to solve. I haven't written any Python at all in at least 6 years.
At the top of this program I'm trying to execute, I have this:
from mycompany.initializer import Configurator
I'm running this program from a directory called:
/usr/code/myapp/migrate
The "mycompany" python module is located in:
/usr/code/mycompany
What path or other variable do I need to export in my user account so that above program can find the appropriate Python module?
Upvotes: 0
Views: 100
Reputation: 578
You can manually add the path (like Kasapo shows). Though I think it would be pythonically preferable if you managed to properly install the module so that it becomes part of the python search path. One way to do that is with PYTHONPATH (ie: exporting PYTHONPATH to include '/usr/code' upon shell start up).
http://docs.python.org/using/cmdline.html
Upvotes: 2
Reputation: 5384
You should be able to add the directory to the system path:
import sys
sys.path.append('/usr/code/')
Also, not sure if this changed in python at any point, but you should have __init__.py
in the 'mycompany' directory (and any module components/submodules in subdirectories...) to properly make it an importable module.
Upvotes: 2