赞
踩
pip 可以对 python 第三方库进行安装、更新、卸载等操作,十分方便。
全称为:package installer for python
,也就是 python 包管理工具。
python 各种各样功能的工具库被存放在一个统一的“仓库”里,名叫 PyPi (Python Package Index),所有的库安装都是从这里调度。
pip是一个命令行程序,一般都在命令行中执行各种操作。例如:在 Windows 下则是通过 cmd 执行。
python 3.4 及以后,已经内置 pip 工具,无需安装。
# 方法一
easy_install pip
# 方法二
# 下载安装 python scripts目录
# 下载网址:https://pypi.org/project/pip/#files
python setup.py install
pip --version
# pip 21.3.1 from d:\programfiles\anaconda\lib\site-packages\pip (python 3.6)
pip install --upgrade pip
pip help
pip install package_name
pip install package_name==1.1.1
# pip install matplotlib==3.4.1
pip install -r D:\\requirements.txt
'''
pickleshare==0.7.5
prompt-toolkit==3.0.18
'''
离线安装, wheel 文件时库的源文件,可以下载后通过本地安装。
# 离线安装
# 1.找到对应的.whl文件
# https://www.lfd.uci.edu/~gohlke/pythonlibs/
# 2.下载对应的版本
# 3.同目录下cmd执行
pip install matplotlib‑3.4.1‑cp39‑cp39‑win_amd64.whl
pip uninstall package_name
pip install --upgrade package_name
pip show -f package_name ''' pandas\tests\series\methods\__pycache__\test_isin.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_nlargest.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_pct_change.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_quantile.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_rank.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_reindex_like.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_rename.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_rename_axis.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_replace.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_reset_index.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_round.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_searchsorted.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_shift.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_sort_index.cpython-36.pyc pandas\tests\series\methods\__pycache__\test_sort_values.cpython-36.pyc '''
pip list
'''
C:\Users\Hider>pip list
Package Version
---------------------------------- ---------
alabaster 0.7.10
anaconda-client 1.6.9
anaconda-navigator 1.7.0
anaconda-project 0.8.2
asn1crypto 0.24.0
astroid 1.6.1
astropy 2.0.3
attrs 17.4.0
'''
pip freeze > requirements.txt
'''
C:\Users\Hider>pip freeze
alabaster==0.7.10
anaconda-client==1.6.9
anaconda-navigator==1.7.0
anaconda-project==0.8.2
asn1crypto==0.24.0
astroid==1.6.1
astropy==2.0.3
attrs==17.4.0
Babel==2.5.3
backports.shutil-get-terminal-size==1.0.0
'''
pip list -o
# 比较慢 需要一个个核查
'''
C:\Users\Hider>pip list -o
Package Version Latest Type
------------------------ --------- --------- -----
alabaster 0.7.10 0.7.12 wheel
asn1crypto 0.24.0 1.4.0 wheel
astroid 1.6.1 2.9.3 wheel
astropy 2.0.3 4.1 wheel
attrs 17.4.0 21.4.0 wheel
Babel 2.5.3 2.9.1 wheel
beautifulsoup4 4.6.0 4.10.0 wheel
bitarray 0.8.1 2.3.5 sdist
'''
`pip check package_name
'''
C:\Users\Hider>pip check pandas
notebook 5.4.0 requires ipykernel, which is not installed.
jupyter 1.0.0 requires ipykernel, which is not installed.
jupyter-console 5.2.0 requires ipykernel, which is not install
ipywidgets 7.1.1 requires ipykernel, which is not installed.
'''
# 保存为whl格式 #学习中遇到问题没人解答?小编创建了一个Python学习交流群:725638078 pip download package_name -d '路径' ''' C:\Users\Hider>pip download pandas -d "C:\Users\Hider" Collecting pandas Using cached pandas-1.1.5-cp36-cp36m-win_amd64.whl (8.7 MB) Collecting numpy>=1.15.4 Using cached numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2 MB) Collecting pytz>=2017.2 Downloading pytz-2021.3-py2.py3-none-any.whl (503 kB) |████████████▌ | 194 kB 7.4 kB/s eta 0:00:42 |█████████████ | 204 kB 7.3 kB/s eta 0:00:41 |██████████████ | 215 kB 6.5 kB/s eta 0:00:4 |██████████████ | 225 kB 6.5 kB/s eta 0:00:4 '''
国外服务器的源速度比较慢,可以从国内的镜像源下载,例如:清华源、豆瓣源、阿里云源等。
但镜像源数据有滞后性,比如清华源的 pypi 镜像每 5 分钟同步一次。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package matplotlib
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
设为默认后,以后安装库都是从清华源下载,而且无需再加镜像源网址。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。