capless/warrant

pip install: ImportError: No module named 'pip.req'

strk opened this issue · 4 comments

strk commented
~$ pip --version
pip 10.0.0b2 from /usr/local/lib/python3.4/dist-packages/pip-10.0.0b2-py3.4.egg/pip (python 3.4)
~$ pip install --user warrant-ext
Collecting warrant-ext
  Using cached warrant-ext-0.2.0.5.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-i1hxw5f7/warrant-ext/setup.py", line 4, in <module>
        from pip.req import parse_requirements
    ImportError: No module named 'pip.req'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-i1hxw5f7/warrant-ext/
strk commented

pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4) successfully installs warrant-ext so I guess this issue should go to pip, not here...

This is not pip's fault. The official docs warn against using pip's internals, such as pip.req in this case. Version 10 of pip was just released and broke most code using their internal APIs, as announced here: Announcement: Pip 10 is coming, and will move all internal APIs.

One solution would be to manually list the requirements in setup.py instead of parsing them from requirements.txt. Another solution would be to use the packaging package and their Requirements API: https://packaging.pypa.io/en/latest/requirements/

A more direct fix would be this simple function to replace the pip.req.parse_requirements():

def parse_requirements(filename):
    """ load requirements from a pip requirements file """
    lineiter = (line.strip() for line in open(filename))
    return [line for line in lineiter if line and not line.startswith("#")]

This is fixed in develop and will be in v0.7.