美文网首页
pip下载、安装、更新Python包及下载速度慢解决方案

pip下载、安装、更新Python包及下载速度慢解决方案

作者: 不玩了啊 | 来源:发表于2020-03-12 08:48 被阅读0次

pip下载、安装、更新Python包及下载速度慢解决方案

分类: Python

使用pip命令在CMD界面为python进行包相关操作主要有:

1、查看已经​安装的包:

pip list

2、查看已经过期的包:

​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内置的非常好用的下载工具,基本可以下载全部的python库。它还有一个非常好的特点,当你安装一个库的时候,它会自动帮你安装所有这个库的依赖库。完全一键式操作。非常方便。但是由于pipy网站是国外网站,很容易会被墙,导致经常下载速度非常慢,经常超时。

解决方式: 更改pip的数据源。目前国内比较知名的有豆瓣的,清华的。都是pipy官网的镜像。

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

​清华:https://pypi.tuna.tsinghua.edu.cn/simple

​安装命令为:

pip install -i 网址 所需要安装的库名

​例如: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库。

其他类似除此之外,还可以通过设置配置文件永久更改pip数据源windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下​

​[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' 回车,自动完成美化;

调试ipython界面或cmd界面清屏使用cls命令,

Linux系统清屏,使用clear命令

8、第三方库打包保存和安装

【步骤一】:打包已安装的依赖包

pip freeze >requirements.txt #生成已安装包清单

如本地保留了之前下载的各依赖包,直接将各whl/tar/zip包保存到某个文件夹下,如d:\packages

如本地未保留之前下载的各依赖包whl/tar/zip包,则需要用下面的命令从网络下载安装

pip install -r requirements.txt#从网络上下载清单中的包(此命令依赖外网环境)

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

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

相关文章

网友评论

      本文标题:pip下载、安装、更新Python包及下载速度慢解决方案

      本文链接:https://www.haomeiwen.com/subject/yhiejhtx.html