Through the proxy — conda, git and pip | by Thomas Bury | Towards Data Science

Have you ever been tempted to burn your company down to ashes, up to the last server and leave to start a hermit life in the Siberian tundra because of the company’s proxy?
If yes, don’t buy yet your survival kit. Here is an effortless way to automate the proxy settings for Conda, GIT and pip in a single step.
When working for a company, you will, most than likely, be working with a proxy. Without setting the proxy, conda, pip and git will not be able to connect to the outside world. And therefore, you’ll not be able to install packages and reach out GitHub or any remote VCS.
The security settings might also prevent you to download packages. For setting up conda, pip and git, you can either modify manually the configuration files (e.g. .condarc and pip.ini). However, that can be painful. Especially if there are several users on the laptop. You can also use the command line way but that can be tedious to remember the commands for the three components.
For simplifying the proxy, settings, I’m using either a PowerShell script or a batch script (yes, my company laptop is a windows machine) that you can find in this repo. I’ll explain how to use them to set up the proxy in a single and easy step.
If you can run PowerShell scripts, the easiest is to proceed as follows. If you can’t, I explain at the end how to use a batch script to achieve the same results, still in single step.
Save the PowerShell script cpg-config.ps1 script in a folder of your choice
Open a Windows PowerShell (or an anaconda PowerShell if you have one), ideally as admin (right click --> run as admin)
Navigate to the folder where you saved the script: cd c:\user\folder_name
Run the script: .\cpg-config.ps1 [proxy_address] then enter
PS C:\WINDOWS\system32> cd C:\Users\Projects\cgp-proxyPS C:\Users\Projects\cgp-proxy> .\cpg-config.ps1 [proxy_address]
just replace `[proxy_address]` by your proxy address and all, conda, git and pip will be configured.
You can also configure only one or two of the three components using the optional argument as:
PS C:\WINDOWS\system32> cd C:\Users\Projects\cgp-proxyPS C:\Users\Projects\cgp-proxy> .\cpg-config.ps1 [proxy_address] pip
for configuring only pip for instance. The other possible values are all, conda, pip, git, git-conda, git-pip, conda-pip.
Note that for conda, the script will update the channel order to put defaults as the highest priority and disable ssl_verify.
After running the script, conda, pip and git should be able to connect to the different servers without any issue
While trying to run the PowerShell script, you might encounter the error not digitally signed. If so, you can type the following command in the PowerShell window:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
And type “yes” or “yes to all”
In case conda is not recognize by PowerShell, simply open an anaconda prompt, and use the command
conda init powershell
This step is only necessary for conda users. If you want only to configure pip and git, you can simply use
PS C:\WINDOWS\system32> cd C:\Users\Projects\cgp-proxyPS C:\Users\Projects\cgp-proxy> .\cpg-config.ps1 [proxy_address] git-pip
The “git-pip” value of the optional argument will make the script bypass the conda part of the script.
If you prefer using the command prompt rather than PowerShell, you can use the batch script as follows
Save the cpg-config.bat script in a folder of your choice
Open a Command Prompt, ideally as admin (right click --> run as admin). It is equivalent to do it with Anaconda CMD, not mandatory though.
navigate to the folder where you saved the script: cd c:\user\folder_name
use this command line: cpg-config.bat [proxy_url] all flexible then enter. Replace [proxy_url] by your proxy url (e.g. https://xyz.proxy.company-name:8080)
Of course, you can unset the proxy at any time using
conda config --remove-key proxy_servers.httppip config unset global.proxygit config --global --unset http.proxy