No module named pip.req
I am installing tweepy, but I am running into an error about pip.req. I have pip installed, but for some reason pip.req still can't be found. I did a bunch of research online and the most I could find was some issue about incompatibilities between zapo (?) and python 2.7 causing the same error for some other user. The discussion was unclear about how to solve the problem, though. Thanks!
$ python2 setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from pip.req import parse_requirements
ImportError: No module named pip.req
Solution 1:
This is happening lately because of a change in pip 10.
The fix is pretty easy. You probably have something like:
from pip.req import parse_requirements
Change that to something like:
try: # for pip >= 10
from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements
That should do it.
Solution 2:
I downgraded to pip to 9.0.3 and things worked for me. Command for downgrading pip is
python -m pip install pip==9.0.3
Solution 3:
It looks like it would work if you had this code:
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("#")]
Do this:
- create a directory
pip/
- add an empty file
pip/__init__.py
- add a file
pip/req.py
- put the code above into
pip/req.py
: -
modify the line in
setup.py
reqs = install_reqs
Solution 4:
Instead of importing the function and potentially encountering more issues replace the contents of the setup.py with the following:
#!/usr/bin/env python
#from distutils.core import setup
import re, uuid
from setuptools import setup, find_packages
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("#")]
VERSIONFILE = "tweepy/__init__.py"
ver_file = open(VERSIONFILE, "rt").read()
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
mo = re.search(VSRE, ver_file, re.M)
if mo:
version = mo.group(1)
else:
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
install_reqs = parse_requirements('requirements.txt')
reqs = install_reqs
setup(name="tweepy",
version=version,
description="Twitter library for python",
license="MIT",
author="Joshua Roesslein",
author_email="[email protected]",
url="http://github.com/tweepy/tweepy",
packages=find_packages(exclude=['tests']),
install_requires=reqs,
keywords="twitter library",
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Software Development :: Libraries',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
],
zip_safe=True)
Notice the session argument has been removed from the parse_requirements call.