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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36729023/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:16:47  来源:igfitidea点击:

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

pythongitproxyanacondaconda

提问by Alo

I'm having trouble working with Anaconda behind a proxy at work.

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

When I have have the following environment variables:

当我有以下环境变量时:

http_proxy: http://domain\username:[email protected]:8080
https_proxy: https://domain\username:[email protected]:8080

or just

要不就

http_proxy: http://server\username:[email protected]:8080

set up then git works. But Anaconda does not work. I'm trying to run

设置然后 git 工作。但是 Anaconda 不起作用。我正在努力奔跑

conda update conda

and I get:

我得到:

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

Does Anaconda not work with http? and requires an https proxy? Because I'm thinking my company may not have an https proxy server setup (I've only seen them use http). or sometimes I get the error:

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....

I'm using Windows 7.

我正在使用 Windows 7。

回答by ctrl-alt-delete

you need to create a .condarcfile in you Windows user area:

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

C:\Users\<username>\

The file should contain:

该文件应包含:

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: http://proxy.yourorg.org:port


ssl_verify: False

回答by Sadman Amin

If the above solutions didnt work for you, you can try this.

如果上述解决方案对您不起作用,您可以试试这个。

Go to your PC settings and then to proxy. Just give the proxy setting globally for your pc. When I did it, it worked for me.

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

enter image description here

在此处输入图片说明

回答by Abhishek025

I went on to add HTTP_proxy and HTTPS proxy in the environment variable. The format used was "username:password@proxy_name:port". I then reopened Anaconda prompt. Type "set" to verify the added variables are present in Anaconda environment. Now you can type "spyder" in the Ananconda prompt. This setting worked for me.

我继续在环境变量中添加 HTTP_proxy 和 HTTPS 代理。使用的格式是“ username:password@proxy_name:port”。然后我重新打开了 Anaconda 提示符。键入“ set”以验证添加的变量是否存在于 Anaconda 环境中。现在您可以在 Ananconda 提示符下输入“ spyder”。这个设置对我有用。

Initially I had tried setting the ".condarc file with the proxy parameters and tried "conda update conda" to no luck.

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

回答by yl_low

The below worked for me to permanently set my proxies for Anaconda:

以下为我永久设置了我的 Anaconda 代理:

Go to C:/ProgramData/Anaconda3/etc/

转到 C:/ProgramData/Anaconda3/etc/

If it doesn't already have a conda folder, create it.

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

If it doesn't already have the folders activate.d and deactive.d, create them.

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

Also create env_vars.bat in both folders. Your end structure should look like the snapshot below:

还要在两个文件夹中创建 env_vars.bat。您的最终结构应如下面的快照所示:

enter image description here

在此处输入图片说明

In env_vars.bat in activate.d, paste the following (change it to your own proxies):

在 activate.d 的 env_vars.bat 中,粘贴以下内容(将其更改为您自己的代理):

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/

In env_vars.bat in deactivate.d, paste the following (leave the variables blank):

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

set HTTP_PROXY=
set FTP_PROXY=
set HTTPS_PROXY=

Close and reopen your Anaconda Prompt to activate the changes.

关闭并重新打开 Anaconda Prompt 以激活更改。

回答by Mina HE

The above solution of modifying .condarc doesn't work for me. However I succeed by updating the environment variables in Advanced System Settings in the format https://user:[email protected]:8080.

上述修改 .condarc 的解决方案对我不起作用。但是,我通过以https://user:[email protected]:8080格式更新高级系统设置中的环境变量而成功。

If your password contains special characters, you need escape them as described in Percent-encoding reserved characters , on Wikipedia. https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters

如果您的密码包含特殊字符,您需要按照 Wikipedia 上的 Percent-encoding reserved characters 中所述对它们进行转义。https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters

回答by Frank Wang

See my answer in another post:

请参阅我在另一篇文章中的回答:

The best wayI settled with is to set proxy environment variables right beforeusing condaor pipinstall/update commands. Simply run:

我解决的最好方法使用condapip安装/更新命令之前设置代理环境变量。只需运行:

set HTTP_PROXY=http://username:password@proxy_url:port

set HTTP_PROXY=http://username:password@proxy_url:port

For example, your actual command could be like

例如,您的实际命令可能类似于

set HTTP_PROXY=http://yourname:[email protected]_company.com:8080

set HTTP_PROXY=http://yourname:[email protected]_company.com:8080

If your company uses https proxy, then also

如果您的公司使用 https 代理,那么也

set HTTPS_PROXY=https://username:password@proxy_url:port

set HTTPS_PROXY=https://username:password@proxy_url:port

Once you exit Anaconda prompt then this setting is gone, so your username/password won't be saved after the session.

一旦您退出 Anaconda 提示,此设置就会消失,因此您的用户名/密码不会在会话后保存。

I didn't choose other methods mentioned in Anaconda documentationor some other sources, because they all require hardcoding of username/password into

我没有选择Anaconda 文档或其他一些来源中提到的其他方法,因为它们都需要将用户名/密码硬编码到

  • Windows environment variables (also this requires restart of Anaconda prompt for the first time)
  • Conda .condarcor .netrcconfiguration files (also this won't work for PIP)
  • A batch/script file loaded while starting Anaconda prompt (also this might require configuring the path)
  • Windows 环境变量(这也需要第一次重新启动 Anaconda 提示符)
  • Conda.condarc.netrc配置文件(这也不适用于 PIP)
  • 启动 Anaconda 提示时加载的批处理/脚本文件(这也可能需要配置路径)

All of these are unsafe and will require constant update later. And if you forget where to update? More troubleshooting will come your way...

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

回答by itsergiu

Worked for me with certificate yourcertname.pem: https://aafaqueabdullah.wordpress.com/2017/04/10/ssl-authentication/

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