我在 Windows 上使用 Anaconda 2.7,我的互联网连接使用代理。
以前,当使用 python 2.7(不是 Anaconda)时,我安装了这样的包:
pip install {packagename} --proxy proxy-us.bla.com:123
有没有办法使用代理参数运行 conda
?在 conda help
中没有看到它。
谢谢
您可以通过将 conda 添加到 .condarc
来配置代理,例如
proxy_servers:
http: http://user:pass@corp.com:8080
https: https://user:pass@corp.com:8080
或设置 HTTP_PROXY
和 HTTPS_PROXY
环境变量。请注意,在您的情况下,您需要将方案添加到代理 URL,例如 https://proxy-us.bla.com:123。
请参阅http://conda.pydata.org/docs/config.html#configure-conda-for-use-behind-a-proxy-server。
或者,您可以使用版本 4.4.x 中的以下命令行。
conda config --set proxy_servers.http http://id:pw@address:port
conda config --set proxy_servers.https https://id:pw@address:port
CondaValueError: Key 'proxy_servers.http' is not a known primitive parameter.
我犯的一个错误是将文件另存为 a.condarc
或 b.condarc
。
仅将其另存为 .condarc
并将以下代码粘贴到文件中并将文件保存在您的主目录中。对主机名、用户等进行必要的更改。
channels:
- defaults
show_channel_urls: True
allow_other_channels: True
proxy_servers:
http: http://user:pass@hostname:port
https: http://user:pass@hostname:port
ssl_verify: False
我能够在不输入用户名和密码的情况下让它工作:
conda config --set proxy_servers.https https://address:port
我解决的最佳方法是在之前使用conda
或pip
安装/更新命令设置代理环境变量。只需运行:
set HTTP_PROXY=http://username:password@proxy_url:port
例如,您的实际命令可能是
set HTTP_PROXY=http://yourname:your_password@proxy.your_company.com:8080
如果您的公司使用 https 代理,那么也
set HTTPS_PROXY=https://username:password@proxy_url:port
一旦你退出 Anaconda 提示,这个设置就消失了,所以你的用户名/密码在会话结束后不会被保存。
我没有选择 Anaconda documentation 中提到的其他方法或其他来源,因为它们都需要将用户名/密码硬编码到
Windows 环境变量(这也需要第一次重启 Anaconda 提示符)
Conda .condarc 或 .netrc 配置文件(这也不适用于 PIP)
启动 Anaconda 提示时加载的批处理/脚本文件(这也可能需要配置路径)
所有这些都是不安全的,以后需要不断更新。如果你忘记在哪里更新?更多故障排除将出现在您的面前...
conda install
安装东西
also this won't work for PIP
应以粗体和大写字母突出显示
您可以通过将 conda 添加到 .condarc 来配置代理,例如
proxy_servers:
http: http://user:pass@corp.com:8080
https: https://user:pass@corp.com:8080
然后在 cmd Anaconda Power Prompt (base) PS C:\Users\user> 中运行:
conda update -n root conda
在 Mac 上,对我有用的是钥匙串并更新公司内部存储库的密钥密码。
ssl_verify: False
。可能是您的雇主正在解密您的连接,因此 SSL 证书不是预期的(中间人攻击)ssl_verify: False
,除非你知道你的雇主是你中间的一个人。通过禁用 ssl 验证,您完全禁用了确保 conda ia 下载它应该下载的包的安全检查。请记住,conda 下载的包可以运行任意代码!.condarc
中,并且希望在需要时被要求输入它们,我应该怎么做?