[英]Problem when download Python package and then install from .whl files
我想下載 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
將所有 `.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.11
和Ubuntu 20.04.5 LTS
。 我認為,這個問題是針對依賴關系或不同的OS
。 你能幫我解決這個問題嗎?
您使用 Python 3.11,但上面顯示的輪子適用於 Python 3.10。 您應該在具有相同處理器架構(x64 似乎是您的情況)、相同的操作系統和版本(Ubuntu 20)以及相同的次要 Python 版本(Python 3.11.*,即任何 Python 3.11 但不是Python 3.10) 作為目標主機。
或者在脫機主機上使用 Python 3.10。
您需要使用--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 Packaging User Guide指出 Python wheel 可以是“純 Python wheel”或“平台 wheel”。 當 Python 包包含需要編譯的擴展時,生成的輪子將是特定於平台的,不能安裝在其他不兼容的平台上。
在您的情況下,車輪MarkupSafe-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
是為 Python 3.10 運行時、 manylinux2014和 x86_64 架構機器構建的平台輪。
wheel 文件名在PEP 491中定義,格式為{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
。
擴展名之前文件名的最后三個組成部分稱為“兼容性標簽”。 兼容性標簽表達了包的基本解釋器要求,並在 PEP 425 中有詳細說明。
因此,根據 wheel 的名稱(准確地說,是文件名中的最后三個組件),您可以確定它是純 Python wheel 還是平台 wheel。
帖子中的另一個答案說你需要安裝一個在 Python 標簽中具有相同 miner Python 版本的輪子,但這通常不是真的。
根據PEP 425 :
安裝程序使用這些標簽來決定從潛在構建發行版列表中下載哪個構建發行版(如果有的話)。 安裝程序維護一個它將支持的(pyver、abi、arch)元組列表。 如果構建的發行版的標簽在列表中,則可以安裝它。
這意味着pip
負責決定是否可以在當前系統上安裝發行版。
我們來看看pip
的源代碼。 CandidateEvaluator
在嘗試安裝包時評估可能的分發候選者。
如果您一直跟蹤代碼到_py_interpreter_range
,您會發現舊的 Python 次要版本列表按降序附加到受支持的標簽。
對於 Python 3.11、 Python 3.10
、 Python 3.9
、 Python 3.8
... 都被認為是 pip 支持的標簽。
帶有
--platform
、--python-version
、--implementation
和--abi
選項的 pip 下載提供了為運行 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.