Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip can't create or remove compiled (.pyo) source files #2209

calconst opened this issue Dec 17, 2014 · 2 comments


None yet
3 participants
Copy link

commented Dec 17, 2014

What's expected is an option something like easy_install has to control the optimization level for compiling installed .py files to .pyo files, especially when installing from Wheels. For example,

pip install --optimize=2 mypackage.whl

would install mypackage from the wheel and compile .py files to .pyc and .pyo. Presently, one only gets the .pyc files.

A bigger issue is that if .pyo files are created by some other means, such as executing a module in optimized mode (e.g. python -O), .pyo files are created, but pip doesn't (can't?) uninstall them. Consequently, if Python is executed in optimized mode even after a module is uninstalled, it runs the module as if it is installed!


pip uninstall mypackage

would uninstall .py, .pyc (as done now) and .pyo files.

See this discussion on PIP's mailing list.


This comment has been minimized.

Copy link

commented Feb 4, 2015

I have also run into this problem, specifically with upgrading Django. If I do not remove the .pyo files, it gives me this error:


You have just installed Django over top of an existing
installation, without removing it first. Because of this,
your install may now include extraneous files from a
previous version that have since been removed from
Django. This is known to cause a variety of problems. You
should manually remove the


directory and re-install Django.

Successfully installed django

If I remove the pyo files (with find /usr/local/lib/python2.7/dist-packages/django/ -name '*.pyo' -delete) before running pip install --upgrade Django, then the install completes successfully.

As far as I can tell, this is because /usr/local/lib/python2.7/dist-packages/Django-1.5.4.egg-info/installed-files.txt lists the .py and .pyc files, but not the .pyo files, and pip uninstall (or pip install --upgrade, which seems to uninstall first) only removes files listed in installed-files.txt if installed-files.txt exists.


This comment has been minimized.

Copy link

commented Mar 22, 2017

Closing this, I don't think we want to support a --optimize flag. However the second half of this is now fixed in pip and we will remove .pyo files if they have been created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.