kilojoules kilojoules - 1 month ago 5
Python Question

can I make a virtualenv into an egg

I can make a python egg using setuptools:

python setup.py bdist_egg
. In theory, I should be able to do this for every installed package with a
setup.py
file. Is it possible to encapsulate an entire
virtualenv
virtual python environment to a python egg?

Answer

You shouldn't do this for several reasons

Even if you could manage to do this, it wouldn't work as you'd expect. If the user already had one of the packages inside your egg installed, they would clash, because python eggs don't add additional namespaces.

Also, python eggs are kind of on their way out. If you want to create a binary distribution, you should use the newer python wheels.

If you have a project with dependencies, just declare those dependencies in your setup.py and pip will handle installing them. If you have some dependencies that don't exist on PyPi, or you need a very specific legacy version of a package, just include those packages as a subpackage in your package.

/my_package
    __init__.py
    /libs
        __init__.py
        /non_pypi_package
        /legacy_package 

And then in your code, instead of importing them as

import non_pypy_package

you would use

from my_package.libs import non_pypi_package