Pip 10 no module named pip.req

  • Installing pip using get-pip.py breaks. He says

    Requirement already up-to-date: pip in /tmp/tmpvF6RoH/pip.zip (10.0.0)

  • There is no module named pip.req

when installing the pip module

Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    from pip.req import parse_requirements
ImportError: No module named pip.req
+4
source share
1 answer

Installation

To install using get-pip.py use the -force-reinstall flag:

$ python get-pip.py --force-reinstall

Obviously, this is before fixing the problem https://github.com/pypa/pip/issues/5220


Import from pip

If you have import from pip, for example:

from pip.req import parse_requirements

he will break. Since they are now moved to pip._internal as such:

from pip._internal.req import parse_requirements

However, you will have to use something similar for backward compatibility:

try: # for pip >= 10
    from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
    from pip.req import parse_requirements

Attention!

, , pip , - , : https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program p >

+8

Source: https://habr.com/ru/post/1696187/


All Articles