Override module in virtualenv with local directory

I am new to python and am facing a problem that I cannot get through. I have module A that depends on module B. Usually A loads B and stores it with the rest of the eggs in my virtual package sites. I now have a local version B that I want to use instead of this downloaded version B, but no matter what I seem to be doing, A is still using B in its site packages, not the one I specify in mine PYTHONPATH.

I know my local B is set up correctly because I can use it just fine if I add it to my PYTHONPATH and I am not using virtualenv.

If I open up ipython with local B added to PYTHONPATH, I can see that my sys.path shows the site-package version first and then the directory in my PYTHONPATH. If I do something hacky like reverses the order of the sys.path and tries to load B, it still uses B from site packages. The only way I have found this is to create a symbolic link from B in my package sites to my local B and delete all * .pyc files in my local B. There just has to be a better way to do this ... any help would be amazing. Thank!

I'm not sure if this will make a difference, but for reference, I am using the following versions of things:

  • virtualenv 12.1.1
  • python 2.7
  • modules A and B are internal libraries in my company.
  • Ubuntu 12.04.5 LTS
+3


source to share


2 answers


If you are working on two related projects in which each depends on the other, you can simply remove the "remote" version and use pip install -e

it to install it from your local copy into editable mode .



This will allow your dependent project to see it and automatically see changes in the project upward without requiring any additional work.

+1


source


Python will always look in your installation directory (site packages) for packages before looking in your current directory. If / When it finds a package in the installation directory, it stops looking.

You can explicitly link to your local copy if that's what you want to do.



from . import ModuleB
from .. import ModuleB
#etc

      

0


source







All Articles