国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python中pip安裝非PyPI官網第三方庫的方法

2019-11-25 17:20:23
字體:
來源:轉載
供稿:網友

在python中安裝非自帶python模塊,有三種方式:

1.easy_install
2.pip
3.下載壓縮包(.zip, .tar, .tar.gz)后解壓, 進入解壓縮的目錄后執行python setup.py install命令

本文主要針對pip安裝時可能會碰到的一種情況,及解決辦法:

假如我要安裝pylint模塊,該模塊非python自帶模塊,用import肯定不能導入,需要額外安裝

復制代碼 代碼如下:

>>> import pylint 
Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
ImportError: No module named pylint 

【現象】

執行pip install <modulename>命令,報錯如下:

復制代碼 代碼如下:

D:/>pip install pylint --allow-external pylint 
Downloading/unpacking pylint 
Requirement already satisfied (use --upgrade to upgrade): six in c:/python27/lib/site-packages/six-1 
.8.0-py2.7.egg (from pylint) 
Downloading/unpacking astroid>=1.3.6 (from pylint) 
  Real name of requirement astroid is astroid 
  Could not find any downloads that satisfy the requirement astroid>=1.3.6 (from pylint) 
  Some insecure and unverifiable files were ignored (use --allow-unverified astroid to allow). 
Cleaning up... 
No distributions at all found for astroid>=1.3.6 (from pylint) 
Storing debug log for failure in C:/Users/aaa/pip/pip.log 

【分析】

在Perl中安裝新模塊,一般可以用PPM圖形化工具,也可以用CPAN來安裝,比如說: cpan>install Test::Class, 非常方便,不會碰到這種情況,這種情況主要是因為pip版本問題: pip最新的版本(1.5以上的版本), 出于安全的考
慮,pip不允許安裝非PyPI的URL,因為該安裝文件實際上來自pylint.org,因而導致上面的錯誤!

NOTE:

1. 可以在官方changelog里面查看更改的信息
2. 可以用pip --version來查看pip的版本信息

復制代碼 代碼如下:

C:/>pip --version 
pip 1.5.6 from C:/Python27/lib/site-packages (python 2.7) 

【辦法】

針對上面的情況,既然這個問題是因為pip版本的原因,可以改用pip低一點的版本
方法一: 用pip 1.4版本,再執行pip install pylint命令來安裝
方法二: 執行命令時,加上--allow-all-external, --allow-unverified及依賴包版本(astroid==1.3.6)

復制代碼 代碼如下:

pip install pylint --allow-all-external pylint astroid==1.3.6 --allow-unverified pylint

NOTE:
1. --allow-all-external   # 允許所有外部地址的標簽,只有打上該標簽pip方可下載外部地址模塊
2. --allow-unverified     #  pip沒有辦法校驗外部模塊的有效性,所以必須同時打上該標簽
3. astroid==1.3.6          #  依賴包必須要添加上,并賦予其版本號,pip方能從列表下載    

方法三: 在當前目錄下,新增requirements.txt,內容如下:

復制代碼 代碼如下:

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

再執行: pip install -r requirements.txt
【結論】
1. pip這個設計不夠友好,使用也很不方便,遠不如Perl中的PPM,期待Python中也有這么個工具。
2. 如果碰到這種錯,導致不能安裝模塊的話: 直接下載壓縮包安裝好了。 >>>下載包地址<<<
3. 執行pip -h命令查看更新pip相關的幫助信息

復制代碼 代碼如下:

Usage:    
  pip <command> [options] 
 
Commands: 
  install                     Install packages. 
  uninstall                   Uninstall packages. 
  freeze                      Output installed packages in requirements format. 
  list                        List installed packages. 
  show                        Show information about installed packages. 
  search                      Search PyPI for packages. 
  wheel                       Build wheels from your requirements. 
  zip                         DEPRECATED. Zip individual packages. 
  unzip                       DEPRECATED. Unzip individual packages. 
  bundle                      DEPRECATED. Create pybundles. 
  help                        Show help for commands. 
 
General Options: 
  -h, --help                  Show help. 
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times. 
  -V, --version               Show version and exit. 
  -q, --quiet                 Give less output. 
  --log-file <path>           Path to a verbose non-appending log, that only logs failures. This log is active by default at pip.log. 
  --log <path>                Path to a verbose appending log. This log is inactive by default. 
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port. 
  --timeout <sec>             Set the socket timeout (default 15 seconds). 
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. 
  --cert <path>               Path to alternate CA bundle. 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍山县| 额尔古纳市| 彭阳县| 桦甸市| 醴陵市| 汕尾市| 礼泉县| 双桥区| 颍上县| 紫阳县| 水富县| 赫章县| 郑州市| 翼城县| 康马县| 莲花县| 江源县| 贡觉县| 怀宁县| 刚察县| 罗山县| 江华| 多伦县| 吉安市| 神木县| 孟连| 西贡区| 静乐县| 福建省| 青阳县| 昔阳县| 磴口县| 南开区| 密云县| 丁青县| 广宗县| 望都县| 正镶白旗| 永春县| 若尔盖县| 财经|