最近我无法使用 Pip 下载任何软件包。每次它都会出错status 1,通常是在运行setup.py或构建轮子时。以下是我得到的完整回溯的两个示例:
pip install miniupnpc\nCollecting miniupnpc\n Downloading miniupnpc-2.0.2.tar.gz (67 kB)\n |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 67 kB 1.7 MB/s\n Preparing metadata (setup.py) ... done\nUsing legacy 'setup.py install' for miniupnpc, since package 'wheel' is not installed.\nInstalling collected packages: miniupnpc\n Running setup.py install for miniupnpc ... error\n ERROR: Command errored out with exit status 1:\n command: 'C:\\Users\\--------\\AppData\\Local\\Programs\\Python\\Python310\\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\\\Users\\\\--------\\\\AppData\\\\Local\\\\Temp\\\\pip-install-kjrhsl01\\\\miniupnpc_31f9b0505dac4eff85fe9636cdb81aad\\\\setup.py'"'"'; __file__='"'"'C:\\\\Users\\\\--------\\\\AppData\\\\Local\\\\Temp\\\\pip-install-kjrhsl01\\\\miniupnpc_31f9b0505dac4eff85fe9636cdb81aad\\\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\\Users\\--------\\AppData\\Local\\Temp\\pip-record-8d4qnr7v\\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\\Users\\--------\\AppData\\Local\\Programs\\Python\\Python310\\Include\\miniupnpc'\n cwd: C:\\Users\\--------\\AppData\\Local\\Temp\\pip-install-kjrhsl01\\miniupnpc_31f9b0505dac4eff85fe9636cdb81aad\\\n Complete output (4 lines):\n running install\n running build\n running build_ext\n error: [WinError 2] The system cannot find the file specified\n ----------------------------------------\nERROR: Command errored out with exit status 1: 'C:\\Users\\--------\\AppData\\Local\\Programs\\Python\\Python310\\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\\\Users\\\\--------\\\\AppData\\\\Local\\\\Temp\\\\pip-install-kjrhsl01\\\\miniupnpc_31f9b0505dac4eff85fe9636cdb81aad\\\\setup.py'"'"'; __file__='"'"'C:\\\\Users\\\\--------\\\\AppData\\\\Local\\\\Temp\\\\pip-install-kjrhsl01\\\\miniupnpc_31f9b0505dac4eff85fe9636cdb81aad\\\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\\Users\\--------\\AppData\\Local\\Temp\\pip-record-8d4qnr7v\\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\\Users\\--------\\AppData\\Local\\Programs\\Python\\Python310\\Include\\miniupnpc' Check the logs for full command output.\nRun Code Online (Sandbox Code Playgroud)\nCollecting conda\n Using cached conda-4.3.16.tar.gz (299 kB)\n Preparing metadata (setup.py) ... error\n ERROR: Command errored out with exit status 1:\n command: 'C:\\Users\\--------\\AppData\\Local\\Programs\\Python\\Python310\\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\\\Users\\\\--------\\\\AppData\\\\Local\\\\Temp\\\\pip-install-08mbbg7s\\\\conda_86cbd4f55db04b2aae91751f0497a4e2\\\\setup.py'"'"'; __file__='"'"'C:\\\\Users\\\\--------\\\\AppData\\\\Local\\\\Temp\\\\pip-install-08mbbg7s\\\\conda_86cbd4f55db04b2aae91751f0497a4e2\\\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\\Users\\--------\\AppData\\Local\\Temp\\pip-pip-egg-info-6ybygnj4'\n cwd: C:\\Users\\--------\\AppData\\Local\\Temp\\pip-install-08mbbg7s\\conda_86cbd4f55db04b2aae91751f0497a4e2\\\n Complete output (17 lines):\n\n WARNING: Your current install method for conda only supports conda\n as a python library. You are not installing a conda executable command\n or activate/deactivate commands. If your intention is to install conda\n as a standalone application, currently supported install methods include\n the Anaconda installer and the miniconda installer. If you'd still like\n for setup.py to create entry points for you, use `utils/setup-testing.py`.\n\n Traceback (most recent call last):\n File "<string>", line 1, in <module>\n File "C:\\Users\\--------\\AppData\\Local\\Temp\\pip-install-08mbbg7s\\conda_86cbd4f55db04b2aae91751f0497a4e2\\setup.py", line 35, in <module>\n import conda._vendor.auxlib.packaging # NOQA\n File "C:\\Users\\--------\\AppData\\Local\\Temp\\pip-install-08mbbg7s\\conda_86cbd4f55db04b2aae91751f0497a4e2\\conda\\__init__.py", line 13, in <module>\n from .common.compat import iteritems, text_type\n File "C:\\Users\\--------\\AppData\\Local\\Temp\\pip-install-08mbbg7s\\conda_86cbd4f55db04b2aae91751f0497a4e2\\conda\\common\\compat.py", line 77, in <module>\n from collections import Iterable\n ImportError: cannot import name 'Iterable' from 'collections' (C:\\Users\\--------\\AppData\\Local\\Programs\\Python\\Python310\\lib\\collections\\__init__.py)\n ----------------------------------------\nWARNING: Discarding https://files.pythonhosted.org/packages/74/4e/c533c3136427be62c38cc0e038cabf167bb54489c2ced2f6df903c456861/conda-4.3.16.tar.gz#sha256=a91ef821343dea3ba9670f3d10b36c1ace4f4c36d70c175d8fc8886e94285953 (from https://pypi.org/simple/conda/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.\nRun Code Online (Sandbox Code Playgroud)\n我正在运行 Windows 10 64 位和 Python 3.10.0。我有最新的pip和wheel. 我已经尝试过重新安装 Python 和setuptools.
每当你无法pip install打包时,你的第一反应应该是检查它的 PyPI 页面。
我们以流行的 NumPy 库为例。它的 PyPI 页面是https://pypi.org/project/numpy。除其他信息外,目前还指出:“要求:Python >=3.7,<3.11”。这是截至撰写本文时的最新版本1.21.4 。以前的 NumPy 版本还支持较旧的 Python 安装,例如1.18.0仅需要“Python >=3.5”。
对于最新的 NumPy 版本,其开发人员还指定 Python 版本需要低于 3.11。作为预防措施。截至撰写本文时,最新的 Python 版本是 Python 3.10。换句话说,开发人员不保证这个特定的 NumPy 包能够与尚未发布的未来版本的 Python 配合使用。
NumPy 不是一个纯Python 库。它包含用 C 或其他编程语言编写的“扩展”,比 Python 本身“更接近金属”。这些扩展使 NumPy 变得更快。但它们必须编译为“本机指令”,即特定于操作系统(Windows、Linux、macOS)以及平台架构(32 位、64 位、Apple M1、ARM 等)的代码。
如果要从源代码安装 NumPy,则需要 C 编译器。在 Linux 上,该编译器是预先安装的。例如,在 Windows 上,您必须安装 Visual Studio。但可能还存在其他“构建依赖项”,除了编译器之外,您还需要安装这些东西。这取决于您正在构建/编译. 这就是事情变得复杂的地方,最好避免这些复杂化。
当 Pip 在 PyPI 上只找到一个“源包”,并且该源包包含本机代码时,它会尝试编译它,即从源代码构建它。那里很多事情都可能出错。当出现问题时,Pip 通常会报告ERROR: Command errored out with exit status 1,如问题中所示,尽管实际的退出代码可能不同。
这就是一个很长的说法,你通常希望在 PyPI 上找到预编译的包。特别是如果您使用的是 Windows。在 Linux 上,也许在 macOS 上,事情往往会更顺利。预编译包也称为二进制发行版,通常作为带有.whl文件扩展名的“轮”文件分发。
要查看预编译的轮子是否适用于您的 Python 版本和平台,请单击 PyPI 页面上的“下载文件”并检查显示的列表。对于问题中提到的 MiniUPnP 库,当前版本为 2.2.3,该列表位于https://pypi.org/project/miniupnpc/2.2.3/#files并包含以下.whl文件:
miniupnpc-2.2.3-cp27-cp27m-win32.whl
miniupnpc-2.2.3-cp35-cp35m-win32.whl
miniupnpc-2.2.3-cp36-cp36m-win32.whl
miniupnpc-2.2.3-cp36-cp36m-win_amd64.whl
miniupnpc-2.2.3-cp37-cp37m-win32.whl
miniupnpc-2.2.3-cp37-cp37m-win_amd64.whl
miniupnpc-2.2.3-cp39-cp39-win32.whl
miniupnpc-2.2.3-cp39-cp39-win_amd64.whl
Run Code Online (Sandbox Code Playgroud)
值得注意的是,Python 3.10 没有轮子,cp310文件名中会包含标签。如果存在这样的文件,Pip 本质上只会提取它(因为轮子只不过是美化的 zip 存档)并将其内容复制到您的 Python 安装中,无论它位于您的计算机上的任何位置。但这里安装失败,因为没有轮子,Pip 甚至找不到可以编译的源发行版,这将是一个.tar.gz文件。
对于conda库,它确实找到了源代码发行版,conda-4.3.16.tar.gz但无法编译它。为什么它会失败,留给读者作为练习。
更重要的是,wheel 作为一种打包格式,也用于纯 Python 库,即那些不包含本机扩展的库。例如,PySerial 库的 PyPI 页面(当前)仅列出了两个安装包:
pyserial-3.5-py2.py3-none-any.whl
pyserial-3.5.tar.gz
Run Code Online (Sandbox Code Playgroud)
第一个是轮子,第二个是源分布。在这种情况下,几乎没有什么区别。作为一个纯Python包,它不需要编译。这两个文件本质上只包含 Python 源代码,但除此之外没有什么“复杂”的。这就是none和any标签的含义。即使该库尚未更新,您在最新的 Python 版本或未来的 Python 版本上安装它应该不会出现任何问题。(只要 Python 不在其自身语法中引入任何向后不兼容的更改,情况就是如此。)
另一个要点是:如果您坚持使用最新的 Python 版本(无论是最近发布的哪个版本),那么请注意,您想要安装的许多库可能需要新版本。也就是说,新的wheel文件上传到PyPI。也就是说,新版本。即使对于流行的库,开发人员通常也要几个月后才会意识到这一点。因此,也许可以再继续使用以前的 Python 版本一段时间。或者查找您知道需要的库,并确保在升级之前新的轮子(如果需要)已在 PyPI 上发布。
| 归档时间: |
|
| 查看次数: |
3829 次 |
| 最近记录: |