pip 包管理工具
参考:pip 官网
这个命令可以查看配置文件的位置,一般配置全局[global]就行了,需要的话也可以按不同用户单独指定。
shell
pip config debug配置文件的写法,[命令] + 选项 + 选项值。配置文件里面的选项不需要加--,它和命令的选项一一对应,所有命令和选项在这里查看。
txt
[command]
option: 值比如现在要配置install命令的--index-url选项,就可以这样写
txt
[install]
index-url: https://pypi.tuna.tsinghua.edu.cn/simple这样每次使用install命令的时候都会自动加上--index-url选项了。[global]表示全局配置,如果同时配置了单个命令和global,会优先使用单个命令的配置。
下载源
很多时候会下载超时,最好全局指定国内的下载源,这里需要修改pip的配置文件,不同系统文件位置不同。
全局指定
windows
打开pip.ini,如果没有可以手动创建,注意:他是一个隐藏文件。
shell
C:\ProgramData\pip\pip.ini写入配置
txt
[install]
index-url: https://pypi.tuna.tsinghua.edu.cn/simple现在pip不允许http协议的源了,推荐下载源都指定https的。非要http的话可以配置
txt
[global]
trusted-host: 源地址linux
系统自带的python环境可能没有安装pip,运行pip如果报错可以按照他给的提示安装pip,比如
sudo apt install python3-pip
首先需要找到系统级的配置文件目录,就是XDG_CONFIG_DIRS这个环境变量的值,在他目录下创建/pip/pip.conf然后写入配置
找到XDG_CONFIG_DIRS的位置,一般是在/etc/xdg
shell
# 这个命令可以输出他的值,有多个值会用 : 隔开
echo $XDG_CONFIG_DIRS在配置文件目录下创建/pip/pip.conf并写入配置
shell
cd /etc/xdg
mkdir pip
sudo vim pip.conf写入下面的配置
text
[install]
index-url: https://pypi.tuna.tsinghua.edu.cn/simple临时指定
使用install的-i选项可以单独指定这次下载的源
shell
pip install fastapi -i https://pypi.tuna.tsinghua.edu.cn/simple导出 requirements.txt
windows
shell
# 导出
pip freeze > requirements.txt
# 安装
pip install -r requirements.txtlinux
shell
python -m pip freeze > requirements.txt
python -m pip install -r requirements.txt