Python Virtualenv 特定的 pip 配置文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35638576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Virtualenv specific pip config files
提问by Luke Exton
I need to use different pip config files depending on which project I'm currently working on. Each project pulls from a separate pypi repo and needs its own block in my .pip/pip.conf file
我需要根据我当前正在处理的项目使用不同的 pip 配置文件。每个项目都从一个单独的 pypi 存储库中提取,并且在我的 .pip/pip.conf 文件中需要自己的块
[global]
timeout = 60
index-url = <my_custom_pypi_repo>
Is there a way to provide a pip.conf file on a virtualenv specific basis?
有没有办法在特定于 virtualenv 的基础上提供 pip.conf 文件?
Ideally when I run
理想情况下,当我跑步时
workon env1
pip install env1_package
It would only try and download from the env1 config file
它只会尝试从 env1 配置文件下载
And similar for env2 Ideally when I run
与 env2 类似 理想情况下,当我运行时
workon env2
pip install env2_package
I would like it to not request this package from the env1 pypi server.
我希望它不要从 env1 pypi 服务器请求这个包。
采纳答案by Luke Exton
Found this after I had posted the question:
在我发布问题后发现了这个:
https://pip.pypa.io/en/stable/user_guide/#config-file
https://pip.pypa.io/en/stable/user_guide/#config-file
~/.pip/pip.conf
You will need to set:
您需要设置:
~/.virtualenvs/env1/pip.conf
~/.virtualenvs/env2/pip.conf
It will still inherit from:
它仍然会继承自:
~/.pip/pip.conf
But will allow it to be overwritten for each environment.
但是将允许它为每个环境覆盖。
回答by sql_knievel
Just to update the answer here with the latest from the pip documentation:
只是用pip 文档中的最新信息更新这里的答案:
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
在 virtualenv 中:
在 Unix 和 macOS 上,文件是 $VIRTUAL_ENV/pip.conf
在 Windows 上,文件是:%VIRTUAL_ENV%\pip.ini
The $VIRTUAL_ENV environment variable gets set once you've activated the particular virtual environment you're interested in.
一旦您激活了您感兴趣的特定虚拟环境,就会设置 $VIRTUAL_ENV 环境变量。