安装管理
安装包
在线安装
安装whl
# 使用绝对路径 whl
pip install C:\Users\xxx\Downloads\python_dateutil-2.5.3-py2.py3-none-any.whl
常用源
- 官方源:
https://pypi.python.org/simple
- 百度
https://mirror.baidu.com/pypi/simple
- 阿里云
https://mirrors.aliyun.com/pypi/simple/
- 豆瓣
https://pypi.douban.com/simple/
- 清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/
- 中国科学技术大学
http://pypi.mirrors.ustc.edu.cn/simple/
- 华中科技大学
http://pypi.hustunique.com/
注意:
- 更换源时需要同时配置
index-url
和trusted-host
两个字段。
安装软件
pip install package_name
# 指定版本
pip install package_name==package_version
源管理
查看配置和显示读取配置的路径
pip -v config list
修改源
windows
配置文件pip.ini
存放目录:start $ENV:APPDATA\pip\
# - powershell运行
# 进入 %APPDATA% 目录 创建Pip和文件pip.ini
cd %APPDATA%
start $ENV:APPDATA
start $ENV:APPDATA\pip\
MAIN_DB_1
# pip.ini添加内容:
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple # 这里可以替换成你需要的源
# 同时修改 trusted-host
trusted-host = pypi.tuna.tsinghua.edu.cn
linux
配置文件:~/.pip/pip.conf
mkdir -p ~/.pip/
vim ~/.pip/pip.conf
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
安装pip
- 下载get-pip.py - https://bootstrap.pypa.io/get-pip.py
- 修改嵌入版下,pythonxx._pth文件 去掉
#import site
前的 #号,即放开import site
; python.exe get-pip.py
下载并安装pip- 修改 pyexpat.pyd 文件,在内部添加
Lib\site-packages
,这样嵌入版的python就能识别第三方模块
升级
python -m pip install --upgrade pip --trusted-host pypi.tuna.tsinghua.edu.cn -i https://pypi.tuna.tsinghua.edu.cn/simple/
./python.exe -m pip install --upgrade pip --trusted-host pypi.tuna.tsinghua.edu.cn
./python.exe -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
# 升级pip到最新版
pip install -U pip setuptools
pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install numpy matplotlib scipy -i https://pypi.tuna.tsinghua.edu.cn/simple/
嵌入版python安装pip
安装pip https://blog.csdn.net/doctorone/article/details/88704880
- 下载get-pip.py - https://bootstrap.pypa.io/get-pip.py
- 修改嵌入版下,pythonxx._pth文件 去掉
#import site
前的 #号,即启用import site
; - 执行
python.exe get-pip.py
- 通过 python get-pip.py 下载并安装pip
- 修改 pyexpat.pyd 文件,在内部添加
Lib\site-packages
生成requirements.text
- 生成
requirements
文件
pip freeze > requirements.txt
pip install pipreqs
pipreqs ./ --encoding=utf8
- 安装依赖
pip install -r requirements.txt
常见错误
The repository located at
将源的http更换成https,或者使用https的其他源即可
多版本python重置pip
pythonxx -m pip install --upgrade pip --force-reinstall
出现sslerror的问题
C:\Python27\ArcGIS10.2\python.exe: No module named pip
PS W:\CPS\python\python310_64> .\python.exe -m pip install -U --force-reinstall pip
>>
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)'))': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)'))': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)'))': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)'))': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)'))': /simple/pip/
ERROR: Could not find a version that satisfies the requirement pip (from versions: none)
ERROR: No matching distribution found for pip
WARNING: There was an error checking the latest version of pip.
解决方法1:
通过豆瓣源指定安装最新版的pip
./python -m pip install lightgbm -i http://pypi.douban.com/simple --trusted-host pypi.douban.com