下载Python包然后从.whl文件安装时出现问题



我想下载Python包pipy.org并将它们移动到另一台机器上,最后将该包与下载的.whl文件一起安装在该机器上这是requirements.txt文件:

amqp==5.1.1
anytree==2.8.0
asgiref==3.5.2
async-timeout==4.0.2
attrs==22.1.0
autobahn==22.7.1
Automat==22.10.0
beautifulsoup4==4.11.1
billiard==3.6.4.0
celery==5.2.7
certifi==2022.9.24
cffi==1.15.1
channels==4.0.0
channels-redis==4.0.0
charset-normalizer==2.1.1
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==38.0.3
daphne==4.0.0
Deprecated==1.2.13
Django==4.0.8
django-celery-beat==2.3.0
django-celery-results==2.4.0
django-filter==22.1
django-jalali==6.0.0
django-timezone-field==5.0
djangorestframework==3.14.0
djangorestframework-simplejwt==5.2.2
drf-yasg==1.21.4
et-xmlfile==1.1.0
gunicorn==20.1.0
h2==4.1.0
hpack==4.0.0
hyperframe==6.0.1
hyperlink==21.0.0
idna==3.4
incremental==22.10.0
inflection==0.5.1
itypes==1.2.0
jdatetime==4.1.0
Jinja2==3.1.2
kombu==5.2.4
lxml==4.9.1
MarkupSafe==2.1.1
msgpack==1.0.4
multitasking==0.0.11
numpy==1.23.3
openpyxl==3.0.10
packaging==21.3
pandas==1.5.0
pandas-datareader==0.10.0
Pillow==9.2.0
priority==1.3.0
prompt-toolkit==3.0.31
psutil==5.9.2
psycopg2==2.9.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
PyJWT==2.6.0
pyOpenSSL==22.1.0
pyparsing==3.0.9
python-crontab==2.6.0
python-dateutil==2.8.2
python-dotenv==0.21.0
pytz==2022.4
redis==4.3.4
requests==2.28.1
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.7
service-identity==21.1.0
simplejson==3.17.6
six==1.16.0
soupsieve==2.3.2.post1
sqlparse==0.4.3
Twisted==22.10.0
txaio==22.2.1
typing_extensions==4.4.0
tzdata==2022.5
Unidecode==1.3.6
uritemplate==4.1.1
urllib3==1.26.12
vine==5.0.0
wcwidth==0.2.5
wrapt==1.14.1
yfinance==0.1.74
zope.interface==5.5.1

我下载了以下包:

pip download -r requirements.txt

这是~/LocalPythonPackage目录下的下载包列表:

→ ls 
amqp-5.1.1-py3-none-any.whl                                             lxml-4.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
anytree-2.8.0-py2.py3-none-any.whl                                      MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
asgiref-3.5.2-py3-none-any.whl                                          msgpack-1.0.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
async_timeout-4.0.2-py3-none-any.whl                                    multitasking-0.0.11-py3-none-any.whl
attrs-22.1.0-py2.py3-none-any.whl                                       numpy-1.23.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
autobahn-22.7.1.tar.gz                                                  openpyxl-3.0.10-py2.py3-none-any.whl
Automat-22.10.0-py2.py3-none-any.whl                                    packaging-21.3-py3-none-any.whl
beautifulsoup4-4.11.1-py3-none-any.whl                                  pandas-1.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
billiard-3.6.4.0-py3-none-any.whl                                       pandas_datareader-0.10.0-py3-none-any.whl
celery-5.2.7-py3-none-any.whl                                           Pillow-9.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
certifi-2022.9.24-py3-none-any.whl                                      priority-1.3.0-py2.py3-none-any.whl
cffi-1.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl  prompt_toolkit-3.0.31-py3-none-any.whl
channels-4.0.0-py3-none-any.whl                                         psutil-5.9.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
channels_redis-4.0.0-py3-none-any.whl                                   psycopg2-2.9.4.tar.gz
charset_normalizer-2.1.1-py3-none-any.whl                               pyasn1-0.4.8-py2.py3-none-any.whl
click-8.1.3-py3-none-any.whl                                            pyasn1_modules-0.2.8-py2.py3-none-any.whl
click_didyoumean-0.3.0-py3-none-any.whl                                 pycparser-2.21-py2.py3-none-any.whl
click_plugins-1.1.1-py2.py3-none-any.whl                                PyJWT-2.6.0-py3-none-any.whl
click_repl-0.2.0-py3-none-any.whl                                       pyOpenSSL-22.1.0-py3-none-any.whl
constantly-15.1.0-py2.py3-none-any.whl                                  pyparsing-3.0.9-py3-none-any.whl
coreapi-2.3.3-py2.py3-none-any.whl                                      python-crontab-2.6.0.tar.gz
coreschema-0.0.4.tar.gz                                                 python_dateutil-2.8.2-py2.py3-none-any.whl
cryptography-38.0.3-cp36-abi3-manylinux_2_28_x86_64.whl                 python_dotenv-0.21.0-py3-none-any.whl
daphne-4.0.0-py3-none-any.whl                                           pytz-2022.4-py2.py3-none-any.whl
Deprecated-1.2.13-py2.py3-none-any.whl                                  redis-4.3.4-py3-none-any.whl
Django-4.0.8-py3-none-any.whl                                           requests-2.28.1-py3-none-any.whl
django_celery_beat-2.3.0-py3-none-any.whl                               ruamel.yaml-0.17.21-py3-none-any.whl
django_celery_results-2.4.0-py3-none-any.whl                            ruamel.yaml.clib-0.2.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
django_filter-22.1-py3-none-any.whl                                     service_identity-21.1.0-py2.py3-none-any.whl
django_jalali-6.0.0-py3-none-any.whl                                    setuptools-65.6.3-py3-none-any.whl
djangorestframework-3.14.0-py3-none-any.whl                             simplejson-3.17.6-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
djangorestframework_simplejwt-5.2.2-py3-none-any.whl                    six-1.16.0-py2.py3-none-any.whl
django_timezone_field-5.0-py3-none-any.whl                              soupsieve-2.3.2.post1-py3-none-any.whl
drf_yasg-1.21.4-py3-none-any.whl                                        sqlparse-0.4.3-py3-none-any.whl
et_xmlfile-1.1.0-py3-none-any.whl                                       Twisted-22.10.0-py3-none-any.whl
gunicorn-20.1.0-py3-none-any.whl                                        txaio-22.2.1-py2.py3-none-any.whl
h2-4.1.0-py3-none-any.whl                                               typing_extensions-4.4.0-py3-none-any.whl
hpack-4.0.0-py3-none-any.whl                                            tzdata-2022.5-py2.py3-none-any.whl
hyperframe-6.0.1-py3-none-any.whl                                       Unidecode-1.3.6-py3-none-any.whl
hyperlink-21.0.0-py2.py3-none-any.whl                                   uritemplate-4.1.1-py2.py3-none-any.whl
idna-3.4-py3-none-any.whl                                               urllib3-1.26.12-py2.py3-none-any.whl
incremental-22.10.0-py2.py3-none-any.whl                                vine-5.0.0-py2.py3-none-any.whl
inflection-0.5.1-py2.py3-none-any.whl                                   wcwidth-0.2.5-py2.py3-none-any.whl
itypes-1.2.0-py2.py3-none-any.whl                                       wrapt-1.14.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
jdatetime-4.1.0-py3-none-any.whl                                        yfinance-0.1.74-py2.py3-none-any.whl
Jinja2-3.1.2-py3-none-any.whl                                           zope.interface-5.5.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl

和复制后的所有'。当文件被写入计算机时,我运行了下面的代码:

pip install --no-index --find-links ~/LocalPythonPackage -r requirements.txt

但是我得到了这个错误:

ERROR: Could not find a version that satisfies the requirement MarkupSafe==2.1.1 (from versions: none)
ERROR: No matching distribution found for MarkupSafe==2.1.1

我在两台计算机中使用python3.11Ubuntu 20.04.5 LTS。我认为,这个问题是依赖或不同的OS。你能帮我解决这个问题吗?

TL;DR

您需要使用--platform--only-binary=:all:(有时也需要指定--abi--python-version)标志来下载与您的安装目标机器兼容的车轮。

pip3 download --only-binary=:all: --platform manylinux2014_aarch64 -r requirements.txt

(重要:如果您的目标机器不是aarch64架构,请将manylinux2014_aarch64替换为正确的平台标记)


一些车轮依赖于平台

这个错误的发生是因为pip不能安装你在目录中提供的MarkupSafe wheel,因此它说它找不到一个有效的发行版。

既然你提到这两台计算机在Python版本和操作系统发行版上是相同的,我猜你使用的两台计算机在体系结构上是不同的。(例如目标计算机是aarch64)

下面的解释和解决方案是基于这个猜测。

Python封装用户指南指出Python wheel可以是"纯Python wheel";或者一个"月台轮"。当Python包包含需要编译的扩展时,生成的wheel将是特定于平台的,并且不能安装在其他不兼容的平台上。

在您的示例中,轮子MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl是为Python 3.10运行时,许多linux2014和x86_64架构机器构建的平台轮子。

wheel文件名在PEP 491中定义,格式为{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl

文件名扩展名之前的最后三个组成部分称为"兼容性标记"。兼容性标签表达了包的基本解释器需求,在PEP 425中有详细说明。

因此,通过轮的名称(准确地说,是文件名中的最后三个组件),您可以确定它是纯Python轮还是平台轮。

较新的Python版本(除了不同的主要版本)仍然可以安装为较旧的次要版本构建的平台轮

帖子中的另一个答案说你需要在Python标签中安装一个具有相同矿工Python版本的轮子,但这通常不是真的。

根据PEP 425:

安装程序使用这些标记来决定从潜在的已构建发行版列表中下载哪个已构建发行版(如果有的话)。安装程序维护一个它将支持的(pyver, abi, arch)元组列表。如果已构建的发行版的标签在列表中,则可以安装它。

这意味着pip负责决定是否可以在当前系统上安装一个发行版。

让我们看一下pip的源代码。CandidateEvaluator在尝试安装包时评估可能的候选发行版。

如果你一直跟踪代码到_py_interpreter_range,你会发现一个旧的Python小版本列表被按降序添加到支持的标签后面。

For Python 3.11,Python 3.10,Python 3.9,Python 3.8…都被认为是pip支持的标记。

解决方案

pip download(带有--platform--python-version--implementation--abi选项)提供了获取除pip运行的解释器和系统之外的依赖项的能力。当使用这些选项时,需要--only-binary=:all:--no-deps

从https://pip.pypa.io/en/stable/cli/pip_download/.

manylinux2014_aarch64下载MarkupSafe:

$ pip3 download --only-binary=:all: --platform manylinux2014_aarch64 MarkupSafe

并将包准备命令更改为:

pip3 download --only-binary=:all: --platform manylinux2014_aarch64 -r requirements.txt

您使用Python 3.11,但上面显示的轮子是Python 3.10的。您应该在具有相同处理器架构(x64似乎是您的情况),相同操作系统和版本(Ubuntu 20)以及相同次要Python版本(Python 3.11)的主机上下载软件包。*,即任何Python 3.11(但不包括Python 3.10)作为目标主机。

或者在脱机主机上使用Python 3.10。

最新更新