Contents
How do I install python packages in another directory?
You can use –install-option to multiple times to add any of the options you can use with python setup.py install ( –prefix is probably what you want, but there are a bunch more options you could use). But you still need to add d:\somewhere\other\than\the\default to PYTHONPATH to actually use them from that location.
How does python search for packages?
Python imports work by searching the directories listed in sys. path . So Python will find any packages that have been installed to those locations.
How do I add a directory to my python path?
Open up Terminal. Type open . bash_profile. In the text file that pops up, add this line at the end: export PYTHONPATH=$PYTHONPATH:foo/bar….
- On Windows, with Python 2.7 go to the Python setup folder.
- Open Lib/site-packages.
- Add an example. pth empty file to this folder.
- Add the required path to the file, one per each line.
How to import Python package from another directory?
By removing all those __init__.py files you will be able to import files in the namespace package (including subdirectories) when running app.py, but that’s still not want we want. The Python interpreter still doesn’t know how to reach your instance namespace.
How to include packages in a Python project?
This will be enough to get the files included in source distributions. If the setuptools include_package_data option you’re using isn’t enough to get the files installed, you can ask for them to be installed explicitly with something like this in your setup.py: Thanks for contributing an answer to Stack Overflow!
How to configure Python to use additional locations?
You can use the Site-specific configuration hook. “A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path .”
Where does Python search when importing a file?
When importing a file, Python only searches the current directory, the directory that the entry-point script is running from, and sys.path which includes locations such as the package installation directory (it’s actually a little more complex than this, but this covers most cases).