如何使用 anaconda python 启用代理服务器?

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

How to enable proxy servers with anaconda python?

pythonproxyfirewallanaconda

提问by Randall Goodwin

We are trying to get the conda install (on windows 8) to work behind a firewall via a proxy server. Currently, we are able to use pip to install packages while on our company network by using this at the command prompt:

我们正在尝试通过代理服务器让 conda 安装(在 Windows 8 上)在防火墙后面工作。目前,我们可以在公司网络上使用 pip 在命令提示符下安装软件包:

pip install pandas --proxy=http://abc.def.xyz.com:1234

No passwords need to be specified, just the proxy server and port. The conda documentationstates that proxy servers are possible:

无需指定密码,只需指定代理服务器和端口。该畅达文档指出,代理服务器是可能的:

# Proxy settings: http://[username]:[password]@[server]:[port]
proxy_servers:
    http: http://user:[email protected]:8080
    https: https://user:[email protected]:8080

I have tried this with various combinations to see if I can get it to work with or without putting in my username and password.

我已经尝试了各种组合,看看是否可以在输入或不输入用户名和密码的情况下使用它。

# formats tried:
http: http://user:[email protected]:1234
http: http://abc.def.xyz.com:1234

I cannot seem to get it to work. Tried various combinations of quoting things too (passwords have special chars). Also tried with and without the domain\user.

我似乎无法让它工作。也尝试了引用事物的各种组合(密码具有特殊字符)。还尝试使用和不使用域\用户。

I can see under the hood, conda is using urlib3 (while pip may be using urlib proxy handler?). Note that having your username and password in a file is generally frowned upon.

我可以看到,conda 正在使用 urlib3(而 pip 可能正在使用urlib 代理处理程序?)。请注意,将您的用户名和密码放在文件中通常是不受欢迎的。

I know we could set up our own http or file location channel and put all the packages there and add the channel to the .condarc config settings. However I would prefer not to have to manage a repository of packages and versions locally.

我知道我们可以设置我们自己的 http 或文件位置通道并将所有包放在那里并将通道添加到 .condarc 配置设置。但是,我不想在本地管理软件包和版本的存储库。

So.... is there a way to specify, in the .condarc file the proxy server and port (without user and password) so that conda install works behind a firewall just like pip install on the command line? Or even an inline call like pip has and works... something like:

那么....有没有办法在 .condarc 文件中指定代理服务器和端口(没有用户和密码),以便 conda install 在防火墙后面工作,就像命令行上的 pip install 一样?或者甚至像 pip 这样的内联调用也可以使用……例如:

conda install pandas --proxy=abc.def.xyz.com:1234

Thanks in advance...

提前致谢...

PS: I really love conda. I spent last weekend setting up many virtual environments on my home PC. Documentation was great and everything worked flawlessly. Overall, much better than pip... if only we could only get this to work inside our company :)

PS:我真的很喜欢康达。上周末我在家用 PC 上设置了许多虚拟环境。文档很棒,一切都完美无缺。总的来说,比 pip 好多了……如果我们只能让它在我们公司内部工作就好了 :)

回答by Randall Goodwin

Well, this is embarrassing, but good news. I solved my problem with one more attempt at a change in the condarc file.

好吧,这很尴尬,但好消息。我再次尝试更改 condarc 文件,解决了我的问题。

https: https://abc.def.xyz.com:1234

I guess pip worked ok with regular http, while conda's addresses are all https sites:

我猜 pip 可以正常使用 http,而 conda 的地址都是 https 站点:

https://repo.continuum.io/pkgs/free/win-64/

I should have caught that!

我应该抓住那个!

Well, I am now just happy that we have a solution to use conda behind our firewall, and without needing a user and password. Awesome!

好吧,我现在很高兴我们有一个解决方案可以在我们的防火墙后面使用 conda,并且不需要用户和密码。惊人的!

回答by bakayim

Late answer but maybe other people faced with this problem can benefit.

迟到的答案,但也许其他面临这个问题的人可以受益。

Create a .condarc file contaninig :

创建一个 .condarc 文件 contaninig :

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://172.**.*.***:8080
    https: https://172.**.*.***:8080


ssl_verify: False

Change IP adresses with your own proxy settings.

使用您自己的代理设置更改 IP 地址。

Put this file in your user's main folder (for me : C:\Users\bakayim)

将此文件放在用户的主文件夹中(对我来说:C:\Users\bakayim)

Restart your anaconda prompt

重新启动您的 anaconda 提示符

回答by guest12345

what wokred for me was the following .condarcfile

对我来说是以下.condarc文件

channels:
  - r
  - defaults

proxy_servers:
  http: http://username:password@Proxyadresse:Proxyport
  https: https://username:password@Proxyadresse:Proxyport

ssl_verify: true

回答by guest12345

I also set 2 Windows environment variables: (don't know if it was necessary)

我还设置了2个windows环境变量:(不知道有没有必要)

Name: http_proxy

Variable: http://username:password@Proxyadresse:Proxyport

变量:http://username:password@Proxyadresse:Proxyport

Name: https_proxy

Variable: https://username:password@Proxyadresse:Proxyport

变量:https://username:password@Proxyadresse:Proxyport

回答by user1271930

I can confirm that .condarc didn't have desired effect in my case (Windows 7). With conda infoI could verify that it was loaded but it didn't have any effect.

我可以确认 .condarc 在我的情况下没有达到预期的效果(Windows 7)。随着conda info我可以确认它已加载,但它没有任何效果。

I had to set forementioned environment variables in order to get connection from behind a proxy.

我必须设置上述环境变量才能从代理后面获得连接。

I was done as follows in command prompt:

我在命令提示符下按如下方式完成:

set http_proxy=[protocol:your_proxy_address_here:port]
set https_proxy=[protocol:your_proxy_address_here:port]

Remove brackets. To verify (list) your concurrent settings just type: set

删除括号。要验证(列出)您的并发设置,只需键入:set

回答by Gomez NL

The new version of Anaconda comes with .condar file in the user directory C:\Users\User_name\.condarc.

新版本的 Anaconda 在用户目录中带有 .condar 文件C:\Users\User_name\.condarc

so all to do is just to edit the content as below:

所以要做的只是编辑内容如下:

channels:
  - defaults

show_channel_urls: True
allow_other_channels: True

proxy_servers:
    http: http://172.**.*.***:8080
    https: https://172.**.*.***:8080

ssl_verify: true

That's what worked for me.

这就是对我有用的东西。

回答by Abdul Haseeb

Open Anaconda command and execute below command:

打开 Anaconda 命令并执行以下命令:

set HTTP_PROXY=http://username:[email protected]:8080

set HTTPS_PROXY=https://username:[email protected]:8443