[英]module 'pip' has no attribute 'pep425tags'
当我尝试使用 pip 安装.whl
它说:
... is not a supported wheel on this platform
为了解决这个问题,我搜索了互联网,它说我可以输入这个到repl
import pip; print(pip.pep425tags.get_supported())
有了这个我可以看到 pip 支持的标签和版本
但是,当我输入此代码时,它说:
AttributeError: module 'pip' has no attribute 'pep425tags'
怎么了?
(python 3.6 上的点 10.0.1)
如果目标只是获取兼容标签列表,则使用当前版本的pip (例如20.0.2 ):
$ path/to/pythonX.Y -m pip debug --verbose
这对我来说适用于 Python 2.7(在使用该版本的 virtualenv 中):
import wheel.pep425tags
print(wheel.pep425tags.get_supported())
对于 pip v10 使用这个:
import pip._internal; print(pip._internal.pep425tags.get_supported())
使用 Python 3.6.8 和 pip 19.1.1
python -c "import wheel.pep425tags as w print(w.get_supported())"
工作!
输出:
[('cp36', 'cp36m', 'win_amd64'), ('cp36', 'none', 'win_amd64'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ('cp32', 'none', 'any'), ('cp31', 'none', 'any'), ('cp30', 'none', 'any'), ('py3', 'none', 'win_amd64'), ('py36', 'none', 'any'), ('py3', 'none', 'any'), ('py35', 'none', 'any'), ('py34', 'none', 'any'), ('py33', 'none', 'any'), ('py32', 'none', 'any'), ('py31', 'none', 'any'), ('py30', 'none', 'any')]
主要问题是pep425tags
是wheel
模块的内部事物。 我相信它从来没有打算像那样使用,它总是会发生变化。 刚刚我自己面对这个问题我注意到wheel==0.34.1
有pep425tags
而wheel==0.35.0
没有。
所以如果你真的想使用这个模块,请确保pip3 install wheel==0.34.1
。
bash one-liner,适用于带有pip-18.1
Py2.7和Py3.6 :
python3 -c "import wheel.pep425tags as w; print(w.get_supported())" |sed -zE 's/\),/),\n/g'
我的 GNU-Linux 机器中有多个 Python 版本,这给我带来了一些问题。 Python 2.7, 3.4, 3.6, ...
太乱了! 我知道。 :)
每次我使用 python3 并运行此代码时:
import wheel.pep425tags
print(wheel.pep425tags.get_supported())
和你一样,我也遇到了这个错误:
AttributeError: 'module' object has no attribute 'pep425tags'
通过在stackoverflow 中浏览,我注意到以下可能对您有所帮助的一些问题:
了解您的 pip 或 pip3 设置为 Python 的哪个版本很重要:我的pip设置为python 2.7 , pip3也设置为python 3.6 。
首先,检查您的 pip 或 pip3 的版本:
pip -V
或者
pip3 -V
当我使用 pip3 时,结果是:
pip 20.0.2 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
这表明我的pip3使用python3.6 ,这使我直接进入 python3.6 控制台。 在这种情况下,它可以工作并产生结果:
[('cp36', 'cp36m', 'linux_x86_64'), ('cp36', 'abi3', 'linux_x86_64'), ('cp36', 'none', 'linux_x86_64'), ('cp35', 'abi3', 'linux_x86_64'), ('cp34', 'abi3', 'linux_x86_64'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('cp35', 'none', 'any'), ('cp34', 'none', 'any'), ('cp33', 'none', 'any'), ...]
我希望这些步骤对你有用。
我也有这个问题。 但是我按照之前的方法犯了一个错误。 在此处输入图像描述TypeError: get_supported() missing 1 required positional argument: 'archive_root' ,解决方法是在 get_supported() 中添加参数 win_amd64。
import wheel.pep425tags as w
print(w.get_supported("win_amd64")
试试这个,如果你有一个新版本的pip<\/code>并且你只想要
get_supported<\/code>函数调用的结果:
python -c "from pip._internal.utils.compatibility_tags import get_supported; print(get_supported())"
作为警告, pip._internal
不是一个稳定的 API,所以你不想依赖它。 但如果它有帮助(就像对我一样) - 这个答案提供了一种解决问题的方法:
由于 pip 版本 19.3,TargetPython.get_tags() 返回受支持的 PEP 425 标签以检查候选车轮(来源)。 标签按优先顺序(最优先)返回。
from pip._internal.models.target_python import TargetPython
target_python = TargetPython()
pep425tags = target_python.get_tags()
class TargetPython 封装了 Python 解释器的属性,用于 package 安装、下载等。
AMD64
import pip._internal;print(pip._internal.pep425tags.get_supported())
WIN32
import pip;print(pip.pep425tags.get_supported())
然后通过相应的平台轮pip install <.whl>
( https://www.lfd.uci.edu/~gohlke/pythonlibs/ )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.