Python中pip安裝非PyPI官網(wǎng)第三方庫的方法
在python中安裝非自帶python模塊,有三種方式:
1.easy_install
2.pip
3.下載壓縮包(.zip, .tar, .tar.gz)后解壓, 進(jìn)入解壓縮的目錄后執(zhí)行python setup.py install命令
本文主要針對(duì)pip安裝時(shí)可能會(huì)碰到的一種情況,及解決辦法:
假如我要安裝pylint模塊,該模塊非python自帶模塊,用import肯定不能導(dǎo)入,需要額外安裝
>>> import pylint
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pylint
【現(xiàn)象】
執(zhí)行pip install <modulename>命令,報(bào)錯(cuò)如下:
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, 非常方便,不會(huì)碰到這種情況,這種情況主要是因?yàn)閜ip版本問題: pip最新的版本(1.5以上的版本), 出于安全的考
慮,pip不允許安裝非PyPI的URL,因?yàn)樵摪惭b文件實(shí)際上來自pylint.org,因而導(dǎo)致上面的錯(cuò)誤!
NOTE:
1. 可以在官方changelog里面查看更改的信息
2. 可以用pip --version來查看pip的版本信息
C:\>pip --version
pip 1.5.6 from C:\Python27\lib\site-packages (python 2.7)
【辦法】
針對(duì)上面的情況,既然這個(gè)問題是因?yàn)閜ip版本的原因,可以改用pip低一點(diǎn)的版本
方法一: 用pip 1.4版本,再執(zhí)行pip install pylint命令來安裝
方法二: 執(zhí)行命令時(shí),加上--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 # 允許所有外部地址的標(biāo)簽,只有打上該標(biāo)簽pip方可下載外部地址模塊
2. --allow-unverified # pip沒有辦法校驗(yàn)外部模塊的有效性,所以必須同時(shí)打上該標(biāo)簽
3. astroid==1.3.6 # 依賴包必須要添加上,并賦予其版本號(hào),pip方能從列表下載
方法三: 在當(dāng)前目錄下,新增requirements.txt,內(nèi)容如下:
# requirements.txt
--allow-all-external pylint
--allow-unverified pylint
pylint
--allow-all-external astroid==1.3.6
再執(zhí)行: pip install -r requirements.txt
【結(jié)論】
1. pip這個(gè)設(shè)計(jì)不夠友好,使用也很不方便,遠(yuǎn)不如Perl中的PPM,期待Python中也有這么個(gè)工具。
2. 如果碰到這種錯(cuò),導(dǎo)致不能安裝模塊的話: 直接下載壓縮包安裝好了。 >>>下載包地址<<<
3. 執(zhí)行pip -h命令查看更新pip相關(guān)的幫助信息
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.
相關(guān)文章
pyecharts實(shí)現(xiàn)數(shù)據(jù)可視化
這篇文章主要介紹了pyecharts實(shí)現(xiàn)數(shù)據(jù)可視化,pyecharts 是百度開源的,適用于數(shù)據(jù)可視化的工具,配置靈活,展示圖表相對(duì)美觀,順滑,下面更多詳細(xì)內(nèi)容,需要的小伙伴可以參考一下2022-03-03
pandas的to_datetime時(shí)間轉(zhuǎn)換使用及學(xué)習(xí)心得
這篇文章主要給大家介紹了關(guān)于pandas的to_datetime時(shí)間轉(zhuǎn)換使用及學(xué)習(xí)心得的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用pandas具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
PyQt5按下按鍵選擇文件夾并顯示的實(shí)現(xiàn)
這篇文章主要介紹了PyQt5按下按鍵選擇文件夾并顯示的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-03-03
python實(shí)現(xiàn)動(dòng)態(tài)GIF英數(shù)驗(yàn)證碼識(shí)別示例
這篇文章主要為大家介紹了python實(shí)現(xiàn)動(dòng)態(tài)GIF英數(shù)驗(yàn)證碼識(shí)別示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01
正則表達(dá)式的概念介紹和python實(shí)踐應(yīng)用詳解
在Python中正則表達(dá)式是一種強(qiáng)大的文本處理工具,它允許你根據(jù)特定的模式匹配字符串中的子串,這篇文章主要介紹了正則表達(dá)式的概念和python實(shí)踐應(yīng)用的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-10-10

