问题描述
-
使用get-pip.py安装pip中断.它说
Installation of pip using get-pip.py is breaking. it says
Requirement already up-to-date: pip in /tmp/tmpvF6RoH/pip.zip (10.0.0)
没有名为pip.req的模块
No module named pip.req
在安装pip模块时
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from pip.req import parse_requirements
ImportError: No module named pip.req
推荐答案
安装
要使用get-pip.py进行安装,请使用--force-reinstall标志:
For installation using get-pip.py use the --force-reinstall flag:
$ python get-pip.py --force-reinstall
很明显,直到他们解决问题为止 https://github.com/pypa/pip/问题/5220
Obviously this is till they fix the problem https://github.com/pypa/pip/issues/5220
推荐替代pip内部命令
避免在您的requirements.txt
文件中放置任何依赖项链接.而是使用下面提到的方法.您可以直接将依赖项链接放在您的setup.py
文件中.一些著名的软件包还以列表的形式维护setup.py
文件中的要求,并且没有任何requirements.txt
文件
Avoid putting any dependency links in your requirements.txt
file. Instead use the method mentioned below. You can directly put the dependency links in you setup.py
file. Some famous packages also maintain the requirements inside the setup.py
file in the form of a list and don't have any requirements.txt
file
with open('requirements.txt') as f:
install_requires = f.read().strip().split('\n')
setup(
name='app_name',
.
.
install_requires=install_requires,
dependency_links=[
'https://github.com/frappe/python-pdfkit.git#egg=pdfkit'
],
cmdclass = \
{
'clean': CleanCommand
}
)
从点子输入 (错误做法-请勿使用,因为它随时可能会中断!)
Imports from pip (BAD PRACTICE - DO NOT USE as it may break anytime! )
强烈建议您避免,因为如pip用户指南中所述,这些方法不是线程安全的.另外,由于它们是pip的私有方法,因此它们可以随时更改而无需事先通知,从而中断了您的软件包安装!
It is highly recommended that you avoid this because, as mentioned in the pip user guide, these methods are not thread safe. Also since they're pip's private methods, they may change it anytime without any prior notice, thereby breaking your package installation!
如果您从pip导入了任何内容,例如:
If you have any imports from pip, such as:
from pip.req import parse_requirements
它会破裂.由于这些内容已按如下方式移至pip._internal:
it'll break. Since these have been now moved to pip._internal as such:
from pip._internal.req import parse_requirements
但是,为了有效地向后兼容,您必须使用如下所示的内容:
However effectively you'll have to use something like this 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
重要
现在,由于以下多种原因,使用内部pip函数并不是一个好习惯: https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program
Now that said it's not a good practice to use the internal pip functions, due to multiple reasons as mentioned here: https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program
这篇关于pip 10没有名为pip.req的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!