簡體   English   中英

當我嘗試使用不兼容的 python 版本安裝 pip 時,如何獲得更好的錯誤消息?

[英]How do I get a better error message when I try to pip install with an incompatible python version?

我的 package 僅支持 python 3,使用python_requires='>3.6'從 setuptools 強制執行

當我嘗試從 python 2 安裝 pip 時,我收到一個模糊的錯誤

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

這與我打錯了 package 名稱的錯誤相同,這不是很有幫助。

當我使用-vvv運行安裝時,我看到 pip 忽略了預期的 py3 包。

Link requires a different Python (2.7.16 not in: u'>=3.6'):
https://mypypiindex (from https://mypypiindex) (requires-python:>=3.6)

我正在開發的 package 面向我公司的大量開發人員,我想向他們說明解釋器版本限制。

有沒有辦法獲得更好的錯誤信息?

我在 GitHub 中看到了討論,但似乎沒有解決方法。

他們來了:

我使用的解決方法是刪除python_requires然后在頂部手動檢查它

import sys

# we used to use python_requires but we want a better
# error message for people trying to use python 2
MIN_PY_VERSION = (3, 6)
assert sys.version_info >= MIN_PY_VERSION,\
    "ERROR: python version must be greater than {}".format(MIN_PY_VERSION)

當開發人員嘗試使用不兼容的 python 版本進行安裝時,他們將看到

$ pip install .
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://artifactory.local.mycompany.net/artifactory/api/pypi/pypi/simple
Processing XXX
    ERROR: Command errored out with exit status 1:
     command: /XXX/bin/python2.7 -c 'XXX'
         cwd: /private/var/folders/t0/bpn6p6nn3jv_fmz9h_wdlld40003f0/T/pip-req-build-1YAoYX/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/XXX/setup.py", line 11, in <module>
        "ERROR: python version must be greater than {}".format(MIN_PY_VERSION)
    AssertionError: ERROR: python version must be greater than (3, 6)
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

注意:如果您從輪子安裝,這不起作用,因為它們不運行 setup.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM