pip如何配置pip config

2025-10-15 08:06:01

1、首先判断你的平台 Linux/Window/Mac OS

2、可以在多个路径下找到pip.conf,没有则创建,

另外,还可以通过环境变量PIP_CONFIG_FILE来指定配置文件的路径。

Linux:

/etc/pip.conf 

~/.pip/pip.conf 

~/.config/pip/pip.conf 

Windows: 

%APPDATA%\pip\pip.ini 

%HOME%\pip\pip.ini 

C:\Documents and Settings\All Users\Application Data\PyPA\pip\pip.conf (Windows XP) 

C:\ProgramData\PyPA\pip\pip.conf (Windows 7及以后)

Mac OSX: 

~/Library/Application Support/pip/pip.conf 

~/.pip/pip.conf 

/Library/Application Support/pip/pip.conf 

3、类型一:

只要pip命令中出现的选项都可以配置在配置文件中(输入pip命令查看选型),这些选项都可以写在配置文件中。

[global] 

index-url = http://pypi.douban.com/simple #豆瓣源,可以换成其他的源

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

trusted-host = 

    pypi.tuna.tsinghua         #清华

timeout = 120

4、类型二:

pip支持install、download、uninstall、freeze、list、show、search、wheel、hash、completion等多条子命令,这些都可以分别配置。

以pip install为例

输入命令pip help install,就会提示pip install支持的所有选项,在配置文件中,就要部署在install选项下,示例如下:

[install]

ignore-installed = true

no-dependencies = yes

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢