pip下載、安裝、更新Python包及下載速度慢解決方案

pip下載、安裝、更新Python包及下載速度慢解決方案

分類:?Python

使用pip命令在CMD界面為python進行包相關(guān)操作主要有:

1、查看已經(jīng)?安裝的包:

pip list

2、查看已經(jīng)過期的包:

?pip list?--outdated

或?

pip list?--outdated --format=columns?

3、包下載安裝:

pip install package_name

4、單一包更新:

pip install -U pac??kage_name

?5、批量更新包:

?import pip

?from subprocess import call

for dist in pip.get_installed_distributions():

?call("pip install --upgrade " + dist.project_name, shell=True)

pip install pip-review

pip-review --local --interactive

6、python pip下載速度慢的解決方法

?pip是python內(nèi)置的非常好用的下載工具,基本可以下載全部的python庫。它還有一個非常好的特點,當你安裝一個庫的時候,它會自動幫你安裝所有這個庫的依賴庫。完全一鍵式操作。非常方便。但是由于pipy網(wǎng)站是國外網(wǎng)站,很容易會被墻,導致經(jīng)常下載速度非常慢,經(jīng)常超時。

解決方式: 更改pip的數(shù)據(jù)源。目前國內(nèi)比較知名的有豆瓣的,清華的。都是pipy官網(wǎng)的鏡像。

?豆瓣:http://pypi.douban.com/simple/

?清華:https://pypi.tuna.tsinghua.edu.cn/simple

?安裝命令為:

pip install -i 網(wǎng)址 所需要安裝的庫名

?例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple?requests

pip? install?-i? https://pypi.doubanio.com/simple/? --trusted-host pypi.doubanio.com? django

?就是利用清華的鏡像源,下載安裝requests庫。

其他類似除此之外,還可以通過設(shè)置配置文件永久更改pip數(shù)據(jù)源windows下,直接在user目錄中創(chuàng)建一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini,內(nèi)容如下?

?[global]

timeout = 6000

index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]

trusted-host=mirrors.aliyun.com

7、Python代碼美化

使用black進行代碼美化,使用方法如下:

安裝black:pip install -U black

使用方法:cmd界面啟動,black 'python腳本.py' 回車,自動完成美化;

調(diào)試ipython界面或cmd界面清屏使用cls命令,

Linux系統(tǒng)清屏,使用clear命令

8、第三方庫打包保存和安裝

【步驟一】:打包已安裝的依賴包

pip freeze >requirements.txt?#生成已安裝包清單

如本地保留了之前下載的各依賴包,直接將各whl/tar/zip包保存到某個文件夾下,如d:\packages

如本地未保留之前下載的各依賴包whl/tar/zip包,則需要用下面的命令從網(wǎng)絡(luò)下載安裝

pip install -r requirements.txt#從網(wǎng)絡(luò)上下載清單中的包(此命令依賴外網(wǎng)環(huán)境)

-------------------------------------------

packages_list of requirements.txt

alabaster==0.7.11

altgraph==0.16.1

astroid==2.0.2

Babel==2.6.0

backcall==0.1.0

beautifulsoup4==4.6.1

bleach==2.1.3

bs4==0.0.1

certifi==2018.4.16

cffi==1.11.5

chardet==3.0.4

cloudpickle==0.5.3

colorama==0.3.9

cycler==0.10.0

decorator==4.3.0

docutils==0.14

entrypoints==0.2.3

future==0.16.0

get==1.0.3

html5lib==1.0.1

idna==2.7

imagesize==1.0.0

ipykernel==4.8.2

ipython==6.5.0

ipython-genutils==0.2.0

ipywidgets==7.3.1

isort==4.3.4

jedi==0.12.1

Jinja2==2.10

jsonschema==2.6.0

jupyter==1.0.0

jupyter-client==5.2.3

jupyter-console==5.2.0

jupyter-core==4.4.0

keyring==13.2.1

kiwisolver==1.0.1

lazy-object-proxy==1.3.1

lxml==4.2.3

macholib==1.10

MarkupSafe==1.0

matplotlib==2.2.2

mccabe==0.6.1

mistune==0.8.3

msgpack==0.5.6

nbconvert==5.3.1

nbformat==4.4.0

notebook==5.6.0

numpy==1.15.0

numpydoc==0.8.0

packaging==17.1

pandas==0.23.3

pandocfilters==1.4.2

parso==0.3.1

pefile==2017.11.5

pickleshare==0.7.4

pip-review==1.0

post==1.0.2

prometheus-client==0.3.1

prompt-toolkit==2.0.4

psutil==5.4.6

public==1.0.3

pycodestyle==2.4.0

pycparser==2.18

pyflakes==2.0.0

Pygments==2.2.0

pyinstall==0.1.4

PyInstaller==3.3.1

pylint==2.1.0

pyparsing==2.2.0

PyQt5==5.11.2

PyQt5-sip==4.19.12

python-dateutil==2.7.3

pytz==2018.5

pywin32==223

pywin32-ctypes==0.1.2

pywinpty==0.5.4

pyzmq==17.1.0

QtAwesome==0.4.4

qtconsole==4.3.1

QtPy==1.4.2

query-string==1.0.2

request==1.0.2

requests==2.19.1

rope==0.10.7

scikit-learn==0.19.2

scipy==1.1.0

seaborn==0.9.0

Send2Trash==1.5.0

simplegeneric==0.8.1

simplejson==3.16.0

sip==4.19.8

six==1.11.0

sklearn==0.0

snowballstemmer==1.2.1

Sphinx==1.7.6

sphinxcontrib-websupport==1.1.0

spyder==3.3.0

spyder-kernels==1.0.1

terminado==0.8.1

testpath==0.3.1

tornado==5.1

traitlets==4.3.2

tushare==1.2.11

typed-ast==1.1.0

typing==3.6.4

urllib3==1.23

wcwidth==0.1.7

webencodings==0.5.1

widgetsnbextension==3.3.1

wrapt==1.10.11

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容