Skip to content

Pip fails to clean up build/ files after egg_info exception, preventing re|un-installation #602

Closed
@ejucovy

Description

@ejucovy

If you try to install a package whose setup.py egg_info causes a SyntaxError, pip doesn't catch that exception, and terminates without cleaning up the partial installation in build/. This will then prevent any subsequent installation of that package, because pip will always detect that partial installation, try to run egg_info on it, and terminate again with a SyntaxError.

Pip should probably catch the errors in both of those cases. In the first step, it should probably remove the failed installation from build/ and exit with a nicer error message. In the second step, if bad files somehow still exist in build/, it should probably catch exceptions in egg_info and proceed as though no existing files were in build/; or perhaps ask the user whether it should remove the files or cancel the command altogether.

This can be reproduced by installing a non-python-2.4-compatible package in a py2.4 environment, and then trying to install an earlier py2.4-compatible version of the same package. For example:

$ virtualenv.py --python=python2.4 /tmp/django24
$ /tmp/django24/bin/pip install Django
(tmpv)egj@alcibiades:/tmp$ /tmp/django24/bin/pip install Django
Downloading/unpacking Django
  Downloading Django-1.4.tar.gz (7.6Mb): 7.6Mb downloaded
  Running setup.py egg_info for package Django
    Traceback (most recent call last):
      File "<string>", line 14, in ?
      File "/tmp/django24/build/Django/setup.py", line 69, in ?
        version = __import__('django').get_version()
      File "django/__init__.py", line 15
        parts = 2 if version[2] == 0 else 3
                   ^
    SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/egj/.pip/pip.log

$ ls /tmp/django24/build/
Django  pip-delete-this-directory.txt

$ /tmp/django24/bin/pip install Django==1.2
Downloading/unpacking Django==1.2
  Running setup.py egg_info for package Django
    Traceback (most recent call last):
      File "<string>", line 14, in ?
      File "/tmp/django24/build/Django/setup.py", line 69, in ?
        version = __import__('django').get_version()
      File "django/__init__.py", line 15
        parts = 2 if version[2] == 0 else 3
               ^
    SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/egj/.pip/pip.log

You can't uninstall it because it never finished getting installed:

$ /tmp/django24/bin/pip uninstall Django
Cannot uninstall requirement Django, not installed
Storing complete log in /home/egj/.pip/pip.log

So you have to (know how to) remove the partial installation yourself to proceed:

$ rm -rf /tmp/django24/build/
$ /tmp/django24/bin/pip install Django==1.2
Downloading/unpacking Django==1.2
  Downloading Django-1.2.tar.gz (6.2Mb): 6.2Mb downloaded
  Running setup.py egg_info for package Django
    warning: no files found matching '*' under directory 'examples'
Installing collected packages: Django
  Running setup.py install for Django
    changing mode of build/scripts-2.4/django-admin.py from 644 to 755
    warning: no files found matching '*' under directory 'examples'
changing mode of /tmp/django24/bin/django-admin.py to 755
Successfully installed Django
Cleaning up...

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-lockedOutdated issues that have been locked by automationtype: bugA confirmed bug or unintended behavior

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions