Question

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:

  • Push my local change to github and install the package within my virtualenv from there with pip
  • Activate my virtualenv and install the package manually with 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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top