我正在安装tweepy,但是我遇到了关于pip.req的错误。我安装了pip,但由于某种原因pip.req仍然无法找到。我在网上进行了大量研究,我发现的最多是关于zapo(?)和python 2.7之间不兼容的问题导致其他用户出现同样的错误。但是,关于如何解决问题的讨论还不清楚。谢谢!
$ 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
答案 0 :(得分:123)
由于点数10的变化,最近发生了这种情况。
修复非常简单。你可能有类似的东西:
from pip.req import parse_requirements
将其更改为:
try: # for pip >= 10
from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements
应该这样做。
答案 1 :(得分:27)
我降级到了9.0.3,一切对我来说都很有效。 降级点的命令是
python -m pip install pip==9.0.3
答案 2 :(得分:18)
如果你有这个代码,它看起来会起作用:
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("#")]
这样做:
pip/
pip/__init__.py
pip/req.py
pip/req.py
:修改setup.py
reqs = install_reqs
答案 3 :(得分:5)
使用以下内容替换setup.py的内容,而不是导入函数并可能遇到更多问题:
#!/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="tweepy@googlegroups.com",
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)
请注意,会话参数已从parse_requirements调用中删除。
答案 4 :(得分:3)
我在Python 3.7 + pip 18.0中遇到了非常相似的问题:
Traceback (most recent call last):
File "/usr/local/bin/pip-compile", line 7, in <module>
from piptools.scripts.compile import cli
File "/usr/local/lib/python3.7/site-packages/piptools/scripts/compile.py", line 11, in <module>
from pip.req import InstallRequirement, parse_requirements
ModuleNotFoundError: No module named 'pip.req'
解决方案是将pip-tools从1.10升级到2.0:
pip install -U pip-tools
答案 5 :(得分:2)
我遇到了同样的问题。要安装pip,你需要遵循这个https://pypi.python.org/pypi/setuptools一旦你得到easy_install我首先安装了pip,然后运行以下命令。
sudo easy_install pip
sudo python setup.py install
容易。