Skip to content Skip to sidebar Skip to footer

Pip: Why Sometimes Installed As Egg, Sometimes Installed As Files

Where can you force pip to install as 'flat' and not as 'egg'. For me it seems random. Sometimes it gets installed as egg, sometime as flat. pip help install shows only an option -

Solution 1:

This does not solve the question why I get sometimes zipped eggs, and sometimes not. But it helps.

You can use this in your ~/.distutils.cfg to avoid installation of zipped eggs:

[easy_install]
zip_ok = False

Solution 2:

If you are the author of the package, you can use the flag zip_safe=False in setup.py.

setup(
    name = "HelloWorld",
    ...
    zip_safe = False,
)

If you are a user who wants to improve the package, you can install it by pip install -e foo_package. The option -e or --editable installs a project in an editable mode (i.e. setuptools "develop mode"), not zipped. It creates a link from source into site-packages and compiles .../bin scripts, but it doesn't copy the source into "site-packages". Those packages can not be updated automatically. It is the main reason why it is not intended as a usual way of installing packages, but only for those that need to be customized or fixed.

Edit: Django is a typical framework that requires zip_safe=False for its applications, because they are not a pure Python, but they contain also templates with html, css, i18n resources etc. Is your question related to Django?


Solution 3:

I was having this egg-only install problem, and it turned out I had failed to git add the __init__.py in the root of my package. It was driving me crazy that this would work:

pip install .

...but this would fail:

mkdir /tmp/piptest
cd /tmp/piptest
git clone $OLDPWD .
pip install .

It was hard to notice the difference using diff -r . $OLDPWD because there are so many non-committed pyc files and development tool scripts.

This is probably not the answer for this OP, but I hope it helps someone who Googles "pip only installing the egg" as I did.


Solution 4:

I had the same issue as @guettli and solved it by unzipping and extracting the archive first then running:

pip -e install /srv/mypkg-1.1.0

where /srv/mypkg-1.1.0/ is the top level directory of project/package that has a setup.py file in it.

mypkg-1.1.0 was installed in site-packages and mypkg.py was listed in [virtualenv]/bin

note: '-e' flag is optional.

Thanks


Solution 5:

Some docs say:

For maximum performance, Python packages are best installed as zip files.

and

You can pass a True or False value for the zip_safe argument to the setup() function, or you can omit it. If you omit it, the bdist_egg command will analyze your project’s contents to see if it can detect any conditions that would prevent it from working in a zipfile.

So it's probably fine unless... it's not fine in your case. My project tried to read files and failed due to the zipping.

Notably, this only happened with python setup.py install, not pip install . @guettli's fix worked fine, but I put it in setup.cfg:

[easy_install]
zip_ok = False

Post a Comment for "Pip: Why Sometimes Installed As Egg, Sometimes Installed As Files"