Search code examples
pythonpython-2.7virtualenvpython-module

Override module in virtualenv with local directory


I'm rather new to python and am running into an issue that I can't get past. I have a module A that depends on module B. Normally, A downloads B and stores it with the rest of the eggs in my virtualenv site-packages. Now, I have a local version of B that I want to use instead of this downloaded version of B but no matter what I seem to do, A still uses the B in its site packages and not the one that I specify in my PYTHONPATH.

I know that my local B is set up right because I can use it just fine if I add it to my PYTHONPATH and I'm not using virtualenv.

If I open up ipython with the local B prepended to PYTHONPATH, I see that my sys.path lists the site-packages version first, then the directory in my PYTHONPATH. If I do something hacky like reverse the order of sys.path and attempt to load B, it still uses the B from site-packages. The only way I've found to get around this is to create a sym link from the B in my site-packages to my local B and remove all the *.pyc files in my local B. There just has to be a better way to do this... any help would be awesome. Thank you!

I'm not sure this will matter but for reference I'm using the following versions of stuff:

  • virtualenv 12.1.1
  • python 2.7
  • modules A and B are internal libraries at my company
  • Ubuntu 12.04.5 LTS

Solution

  • If you're working on a pair of related projects where one depends on the other, you can just uninstall the "remote" version and use pip install -e to install it from your local copy in editable mode.

    This will let your dependent project see it, and automatically see changes to the upstream project without needing any extra work.