Python relative imports (Just let me use the file system please)
by stuartmitchell on Oct 25, 2009
- 8,029 views
A quick description how one can alter the import path to make packages/modules accessible on the file system. Includes these:...
A quick description how one can alter the import path to make packages/modules accessible on the file system. Includes these:
PYHTHONPATH environment variable
sys.path variable in the Python runtime
file system hierarchy and module accessibility inside (site-/dist-packages, local packages, magic of the __init__.py file, ...)
using .pth files
using setup.py and doing the Packaging Mambo (.deb files, eggs/PyPI packages, ...)
In conclusion after some discussion in the meeting I have decided that the python import statement is not about the file system. This is why it is impossible to give it a filename to import. The import statement is about importing a namespace into your code. The question then becomes how does python find your module to import the namespace. In this case setup.py is the proper way to do things. Use
$python setup.py develop
to make the your modules visible to python and use buildout or virtualenv to sandbox your developement environment from your actual python installation.
- Total Views
- Views on SlideShare
- Embed Views