I have a local git repository
on my machine, let's say under /develop/myPackage
.
I'm currently developing it as a python package (a Django app) and I would like to access it from my local virtualenv
. I've tried to include its path in my PYTHONPATH
(I'm on a Mac)
export PATH="$PATH:/develop/myPackage"
The directory already contains a __init__.py
within its root and within each subdirectory.
No matter what I do but I can't get it work, python won't see my package.
The alternatives are:
pip
python setup.py install
Since I often need to make changes to my code the last two solution would require too much work all the time even for a small change.
Am I doing something wrong? Would you suggest a better solution?
To install Python package from github, you need to clone that repository. pip install . from the locally cloned repo dir will work too.
Install it in editable mode from your local path:
pip install -e /develop/MyPackage
This actually symlinks the package within your virtualenv so you can keep on devving and testing.
The example you show above uses PATH, and not PYTHONPATH. Generally, the search path used by python is partially predicated on the PYTHONPATH environment variable (PATH has little use for this case.)
Try this:
export PYTHONPATH=$PYTHONPATH:/develop/myPackage
Though in reality, you likely want it to be pointing to the directory that contains your package (so you can do 'import myPackage', rather than importing things within the package. That being said, you likely want:
export PYTHONPATH=$PYTHONPATH:/develop/
Reference the python docs here for more information about Python's module/package search path: http://docs.python.org/2/tutorial/modules.html#the-module-search-path
By default, Python uses the packages that it was installed with as it's default path, and as a result PYTHONPATH is unset in the environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With