萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> 程式語言綜合

Python pip 安裝非 PyPI 官方套件解決方案:--allow-external 與 requirements.txt 兩大技巧

pip 1.5+ 出於安全考量,預設封鎖非 PyPI 託管的套件(如 pylint 依賴 astroid 托管於 pylint.org)。嘗試安裝會報 Could not find any downloads that satisfy the requirement 與 Some insecure and unverifiable files were ignored。本文提供三種解決路徑。

錯誤現象重現

> pip install pylint --allow-external pylint
Downloading/unpacking pylint
Downloading/unpacking astroid>=1.3.6 (from pylint)
Could not find any downloads that satisfy the requirement astroid>=1.3.6
Some insecure and unverifiable files were ignored (use --allow-unverified astroid to allow).
No distributions at all found for astroid>=1.3.6

方案一:降級 pip 至 1.4.x(不推薦,安全風險)

pip install pip==1.4.1
pip install pylint

方案二:命令列參數放行(推薦臨時使用)

pip install pylint \
  --allow-all-external \
  --allow-unverified pylint \
  --allow-unverified astroid \
  astroid==1.3.6
  • --allow-all-external:允許所有外部來源
  • --allow-unverified <pkg>:允許特定套件跳過驗證
  • 必須指定依賴套件版本(astroid==1.3.6),否則 pip 無法從外部索引解析相依性

方案三:requirements.txt 批次管理(推薦專案長期使用)

# requirements.txt
--allow-all-external pylint
--allow-unverified pylint
pylint
--allow-all-external astroid==1.3.6
--allow-unverified astroid
pip install -r requirements.txt

替代方案:離線安裝

  1. 下載 .whl 或 .tar.gz:PyPI pylint
  2. pip install pylint-2.17.7-py3-none-any.whl

總結建議

  • pip 此設計不夠友善,遠不如 Perl PPM/CPAN 便利
  • 遇阻優先用 requirements.txt 管理例外清單
  • 長期專案建議建立私有 PyPI(devpi、pypiserver)代理外部套件
  • Python 3.10+ pip 已移除 --allow-unverified,需改用 --index-url 指向私有源
copyright © 萬盛學電腦網 all rights reserved