如何让 Anaconda 在 HTTP 代理(不是 https)后面工作?

How to make Anaconda work behind HTTP proxy (not https)?

我在工作中使用代理背后的 Anaconda 时遇到问题。

当我有以下环境变量时:

http_proxy: http://domain\username:password@corp.com:8080
https_proxy: https://domain\username:password@corp.com:8080

或者只是

http_proxy: http://server\username:password@corp.com:8080

设置然后 git 工作。但是 Anaconda 不起作用。 我正在尝试 运行

conda update conda

我得到:

Could not connect to https://repo.continuum.io/pkgs....
Could not connect to https://repo.continuum.io/pkgs....

Anaconda 不支持 http 吗?并需要 https 代理?因为我认为我的公司可能没有 https 代理服务器设置(我只看到他们使用 http)。 或者有时我会收到错误消息:

File "c\Anaconda2\", line 340, in wait
    waiter.acquire()
KeyboardInterrupt
Could not connect to https://repo.continuum.io/pkgs....
Could not connect to https://repo.continuum.io/pkgs....

我正在使用 Windows 7.

你需要在你的Windows用户区创建一个.condarc文件:

C:\Users\<username>\

文件应包含:

channels:
- defaults

# Show channel URLs when displaying what is going to be downloaded and
# in 'conda list'. The default is False.
show_channel_urls: True
allow_other_channels: True

proxy_servers:
    http: http://proxy.yourorg.org:port
    https: https://proxy.yourorg.org:port


ssl_verify: False

上述修改.condarc 的解决方案对我不起作用。 但是,我成功地以 https://user:pass@corp.com:8080.

格式更新了高级系统设置中的环境变量

如果您的密码包含特殊字符,您需要按照维基百科上的百分比编码保留字符中的说明对它们进行转义。 https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters

我继续在环境变量中添加HTTP_proxyHTTPS_proxy。使用的格式是“用户名:密码@proxy_name:端口”。然后我重新打开 Anaconda 提示符。键入“set”以验证添加的变量是否存在于 Anaconda 环境中。现在您可以在 Ananconda 提示符中键入“spyder”。这个设置对我有用。

最初我曾尝试使用代理参数设置“.condarc 文件”并尝试“conda update conda”但没有成功。

下面的方法让我永久设置了 Anaconda 的代理:

转到 C:/ProgramData/Anaconda3/etc/

如果它还没有 conda 文件夹,请创建它。

如果它还没有文件夹 activate.d 和 deactive.d,请创建它们。

同时在两个文件夹中创建 env_vars.bat。您的最终结构应该类似于下面的快照:

在env_vars.bat中activate.d,粘贴以下内容(改成你自己的代理):

set HTTP_PROXY=http://xx.xx.x.xx:xxxx/
set FTP_PROXY=http://xx.xx.x.xx:xxxx/
set HTTPS_PROXY=https://xx.xx.xxx.xx:xxxx/

在deactivate.d中的env_vars.bat中,粘贴以下内容(将变量留空):

set HTTP_PROXY=
set FTP_PROXY=
set HTTPS_PROXY=

关闭并重新打开您的 Anaconda 提示以激活更改。

为我工作并获得证书yourcertname.pem: https://aafaqueabdullah.wordpress.com/2017/04/10/ssl-authentication/

如果以上解决方案都不适合您,您可以试试这个。

转到您的 PC 设置,然后转到代理。只需为您的电脑全局设置代理。当我这样做时,它对我有用。

中查看我的回答:

我解决的最佳方法之前使用conda或[=11=设置代理环境变量] install/update 命令。只需 运行:

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 提示,此设置就会消失,因此您的 username/password 不会在会话结束后保存。

我没有选择 Anaconda documentation 中提到的其他方法或其他一些来源,因为它们都需要将 username/password 硬编码到

  • Windows 环境变量(这也需要第一次重启Anaconda提示)
  • Conda .condarc.netrc 配置文件(这也不适用于 PIP)
  • A batch/script 文件在启动 Anaconda 提示时加载(这也可能需要配置路径)

所有这些都是不安全的,以后需要不断更新。如果您忘记在哪里更新?您会遇到更多故障排除...

这个方法对我有用:

从目录 ./Anaconda3/Library/bin/./Anaconda3/DLLs.

希望它能回答您的问题

经过反复试验,我们终于在 .condarc 文件中使用以下语法(没有“http://”)(我们有两个这样的文件,一个在 Users 文件夹中,另一个在实际用户的文件夹中)。

proxy_servers:
    http: proxyserver.org:portNumber
    https: proxyserver.org:portNumber

代理服务器必须对 anaconda.org 以及 anaconda.com 进行例外处理。重要!

以下解决方案对我有用:

  1. 打开 Anaconda 提示符
  2. 在 运行 任何 pip 或 conda 命令之前,执行以下命令:

设置HTTPS_PROXY=proxy.yourorg.domain:端口号

设置HTTP_PROXY=proxy.yourorg.domain:端口号


  1. 现在您可以执行任何 pip and/or conda 命令来 install/uninstall 您需要的包。
  2. 就是这样,它应该也适合你(希望如此)

我刚刚在 .condarc 中的代理配置条目后添加了一个斜杠,它神奇地开始工作了。上面的一切都没用。

顺便说一句,我在我的系统上使用 CNTLM 本地代理来进行 kerberos 身份验证,所以我不需要在 .condarc 中如此明显地配置凭据。

proxy_servers:
    http: http://proxy.yourorg.org:port/
    https: http://proxy.yourorg.org:port/