Python 没有名为 pip.req 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25192794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No module named pip.req
提问by
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!
我正在安装 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
采纳答案by hughdbrown
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.pyreqs = install_reqs
- 创建目录
pip/ - 添加一个空文件
pip/__init__.py - 添加文件
pip/req.py - 将上面的代码放入
pip/req.py: 修改行
setup.pyreqs = install_reqs
回答by Bedi Egilmez
I ran into same problem you have. To install pip you need to follow this https://pypi.python.org/pypi/setuptoolsonce you get easy_install I installed pip first and then run the following command.
我遇到了和你一样的问题。要安装 pip,你需要按照这个https://pypi.python.org/pypi/setuptools一旦你得到 easy_install 我首先安装了 pip 然后运行以下命令。
sudo easy_install pip
sudo python setup.py install
easy.
简单。
回答by Matthew Frost
Instead of importing the function and potentially encountering more issues replace the contents of the setup.py with the following:
与其导入函数并可能遇到更多问题,不如将 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="[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.
请注意 session 参数已从 parse_requirements 调用中删除。
回答by mlissner
This is happening lately because of a change in pip 10.
这是最近发生的,因为 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.
应该这样做。
回答by skvp
I downgraded to pip to 9.0.3 and things worked for me. Command for downgrading pip is
我降级到 pip 到 9.0.3,事情对我有用。降级pip的命令是
python -m pip install pip==9.0.3
回答by hdiogenes
I had a very similar problem with Python 3.7 + pip 18.0:
我在 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'
The solution was to upgrade pip-tools from 1.10 to 2.0:
解决方案是将 pip-tools 从 1.10 升级到 2.0:
pip install -U pip-tools

