How To Include A Python .egg Library That Is In A Subdirectory (relative Location)?
Solution 1:
An .egg is just a .zip file that acts like a directory from which you can import stuff.
You can use the PYTHONPATH
variable to add the .egg
to your path, or append a directory to
sys.path
. Another option is to use a .pth
file pointing to the eggs.
For more info see A Small Introduction to Python eggs, Python Eggs and All about eggs.
For example, if your library1.egg
contains a package named foo
, and you add library1.egg
to PYTHONPATH
, you can simply import foo
If you can't set PYTHONPATH
, you can write:
import sys
sys.path.append("library1.egg")
import foo
Solution 2:
You can include each egg on the sys.path, or create a .pth file that mentions each egg.
If you have many eggs that you need in your system I'd recommend using something like buildout, that will make the setup easily replicatable. It will handle the eggs for you.
Post a Comment for "How To Include A Python .egg Library That Is In A Subdirectory (relative Location)?"