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-tools could provide better warnings about unsupported pip versions #428

Closed
alexwlchan opened this issue Dec 21, 2016 · 4 comments
Closed

Comments

@alexwlchan
Copy link

I hit an ImportError when running pip-tools with an older version of pip. Upgrading pip fixed the immediate problem, but the error wasn’t immediately obvious. It would be better if pip-tools printed an explicit warning “your pip is out of date, here’s how to update it” if it detects the user is running with an unsupported version of pip.

Steps to replicate

  1. Create a virtualenv with an outdated version of pip and install pip-tools. On my machine:

    $ virtualenv env
    New python executable in env/bin/python
    Installing setuptools, pip, wheel...done.
    
    $ source env/bin/activate
    
    $ pip --version
    pip 7.1.2 from /Users/alexwlchan/projects/null/env/lib/python2.7/site-packages (python 2.7)
    
    $ pip install pip-tools
    Collecting pip-tools
      Using cached pip_tools-1.8.0-py2.py3-none-any.whl
    Collecting six (from pip-tools)
      Using cached six-1.10.0-py2.py3-none-any.whl
    Collecting click>=6 (from pip-tools)
      Using cached click-6.6-py2.py3-none-any.whl
    Collecting first (from pip-tools)
      Using cached first-2.0.1-py2.py3-none-any.whl
    Installing collected packages: six, click, first, pip-tools
    Successfully installed click-6.6 first-2.0.1 pip-tools-1.8.0 six-1.10.0
    You are using pip version 7.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    
    $ pip freeze
    click==6.6
    first==2.0.1
    pip-tools==1.8.0
    six==1.10.0
    wheel==0.24.0
    You are using pip version 7.1.2, however version 9.0.1 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
  2. Create a basic requirements.in file:

    $ echo 'flask' > requirements.in
  3. Run pip-compile to turn this into a requirements.txt file:

    $ pip-compile

Expected Desired result

One of two outcomes:

  • If I’m using a supported version of pip: success! The requirements.txt file will be created successfully.
  • If I’m using an out-of-date or unsupported version of pip, the command will fail and print an error message explaining the problem, and how I could fix it (not unlike the warnings at the end of the pip commands shown above).

Actual result

I get the following traceback from pip-tools:

$ pip-compile
Traceback (most recent call last):
  File "/Users/alexwlchan/projects/null/env/bin/pip-compile", line 7, in <module>
    from piptools.scripts.compile import cli
  File "/Users/alexwlchan/projects/null/env/lib/python2.7/site-packages/piptools/scripts/compile.py", line 16, in <module>
    from ..repositories import LocalRequirementsRepository, PyPIRepository
  File "/Users/alexwlchan/projects/null/env/lib/python2.7/site-packages/piptools/repositories/__init__.py", line 3, in <module>
    from .pypi import PyPIRepository
  File "/Users/alexwlchan/projects/null/env/lib/python2.7/site-packages/piptools/repositories/pypi.py", line 12, in <module>
    from pip.utils.hashes import FAVORITE_HASH
ImportError: No module named hashes

If I run pip install --upgrade pip, I get upgraded to pip 9.0.1 and everything starts working again. But the error message could stand to be a bit nicer. Something like:

pip-tools requires pip==9.0.1 or higher, you have 7.1.2.
To upgrade your pip, use 'pip install --upgrade pip'.
@alexwlchan
Copy link
Author

alexwlchan commented Dec 21, 2016

Wait, I just went to see whether I could find anything about what versions of pip are supported, and the README says:

$ pip install --upgrade pip  # pip-tools needs pip==6.1 or higher (!)
$ pip install pip-tools

So I guess this is a bug?

Ah, but looking at the commit message for 95ca3fe, I see that you need to have pip >= 8 now. I’ll throw together a patch.

@alexwlchan
Copy link
Author

Ah, it looks like this is already a partially solved problem: there’s assert_compatible_pip_version(), but that’s only called after the internal imports have been done – if you hit a version-specific problem while doing those, you never get to call that code.

@davidovich
Copy link
Contributor

Fixed in #457

@davidovich
Copy link
Contributor

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants