69

I'm using Anaconda 2.7 on windows, and my internet connection uses a proxy.

Previously, when using python 2.7 (Not Anaconda), I installed package like this:

pip install {packagename} --proxy proxy-us.bla.com:123

Is there a way to run conda with proxy argument? didn't see it in conda help.

Thanks

AvidLearner
  • 4,123
  • 5
  • 35
  • 48

7 Answers7

80

Or you can use the command line below from version 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
su79eu7k
  • 7,031
  • 3
  • 34
  • 40
  • This did the job for me! :) – tanaque Feb 20 '18 at 12:03
  • 5
    Probably a bit late now, but I wonder if phyatt had an updated version of anaconda? On 4.3.30 I get `CondaValueError: Key 'proxy_servers.http' is not a known primitive parameter.` – craq Jun 14 '18 at 22:07
  • This worked for me! Weird enough, when I set the values directly in the file, they were not recognized. (conda 4.8.2) – phi Mar 12 '21 at 14:55
  • This is working for both Windows and Linux. Thank you sm. – Bandham Manikanta May 08 '21 at 10:01
  • I'm running a px (https://github.com/genotrance/px) proxy on my host to authenticate with credentials behind corporate firewall. My px is listening on port 3131. I use RUN conda config --set proxy_servers.http http://host.docker.internal:3131 RUN conda config --set proxy_servers.https http://host.docker.internal:3131 RUN conda env create -f environment.yml – Manuel Alves Sep 23 '21 at 09:29
72

You can configure a proxy with conda by adding it to the .condarc, like

proxy_servers:
    http: http://user:pass@corp.com:8080
    https: https://user:pass@corp.com:8080

or set the HTTP_PROXY and HTTPS_PROXY environment variables. Note that in your case you need to add the scheme to the proxy url, like https://proxy-us.bla.com:123.

See http://conda.pydata.org/docs/config.html#configure-conda-for-use-behind-a-proxy-server.

David C
  • 7,204
  • 5
  • 46
  • 65
asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • 2
    Thanks... to be honest, I saw this like much earlier, but I'm more interested in command-line solution, without editing some files... Do you know such? – AvidLearner Jun 29 '15 at 20:53
  • 6
    Setting those environment variables is a command line solution. – asmeurer Jun 29 '15 at 21:40
  • 5
    If you are failing on an SSLError message, make sure you set `ssl_verify: False`. It maybe the case that your employer is decrypting your connection so the SSL certificate is not the one expected (man-in-the-middle attack) – mimoralea Feb 08 '18 at 21:28
  • I would avoid setting `ssl_verify: False`, unless you know for a fact that your employer is the one man in the middling you. By disabling ssl verification, you are completely disabling the security checks that ensure that conda ia downloading the packages it is supposed to. Remember that the packages conda downloads can run arbitrary code! – asmeurer Feb 12 '18 at 21:35
  • 1
    If I don't want to put my user name and password in the `.condarc` for security reason, and prefer to be asked to type them when needed, what should I do? – pe-perry Apr 25 '18 at 06:09
  • @kitman0804 I believe if you omit it it should prompt you to enter it when necessary. – asmeurer Apr 25 '18 at 18:57
  • @asmeurer No it don't. It gives me error message `CondaHTTPError: HTTP 000 CONNECTION FAILED for url ` and said something like `'Tunnel connection failed: 407 Proxy Authorization Required'`, if I don't put my user name and password in the file. – pe-perry Apr 27 '18 at 01:55
  • @kitman0804 I would open an issue at https://github.com/conda/conda/issues about it. – asmeurer May 01 '18 at 21:07
15

One mistake I was making was saving the file as a.condarc or b.condarc.

Save it only as .condarc and paste the following code in the file and save the file in your home directory. Make necessary changes to hostname, user etc.

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
zx485
  • 28,498
  • 28
  • 50
  • 59
Somit
  • 303
  • 2
  • 10
6

The best way I settled with is to set proxy environment variables right before using conda or pip install/update commands. Simply run:

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

For example, your actual command could be like

set HTTP_PROXY=http://yourname:your_password@proxy.your_company.com:8080

If your company uses https proxy, then also

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.

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

  • Windows environment variables (also this requires restart of Anaconda prompt for the first time)
  • Conda .condarc or .netrc configuration files (also this won't work for PIP)
  • A batch/script file loaded while starting Anaconda prompt (also this might require configuring the path)

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

Frank Wang
  • 381
  • 3
  • 7
  • This allows me to create anaconda environments, but I still cannot install stuff with `conda install` – Philipp Nov 02 '20 at 13:42
  • You still have your username/password stored in your command history. It would be a lot safer to type at least the password into a prompt. – Thomas Nov 10 '21 at 15:36
  • `also this won't work for PIP` should be highlighted with bold and caps – VMAtm Apr 24 '22 at 21:06
5

I was able to get it working without putting in the username and password:

conda config --set proxy_servers.https https://address:port
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
Sun
  • 51
  • 1
  • 1
4

You can configure a proxy with conda by adding it to the .condarc, like

proxy_servers:
    http: http://user:pass@corp.com:8080
    https: https://user:pass@corp.com:8080

Then in cmd Anaconda Power Prompt (base) PS C:\Users\user> run:

conda update -n root conda
Vit
  • 41
  • 1
0

On Mac what worked for me was going to keychain and updating the password for the key that for the company's the internal repo.