pip - Setup proxy server settings

By xngo on August 27, 2019

When using pip behind a corporate environment, I got the following error.

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /simple/requests/

The error occurred because all internet access require to go through my corporate outbound HTTP proxy server. In this tutorial, I will show you how you can configure pip to connect through the proxy server.

Get proxy settings

Before you set the proxy settings, you first need to know what they are. You either ask your system administrator or get the information from Internet Explorer. It is much easier to get these information from Internet Explorer than from the system administrator. Here is how to get the information from Internet Explorer.

  1. Open the Internet options of the Internet Explorer.
  2. Navigate to the Connections tab.
  3. At the bottom right, click on the LAN settings button.
  4. The value in the Address input field is the proxy settings that you need. What is before the colon(:) is the server address. What is after the colon(:) is the port number.
    IE - Proxy settings

Use --proxy command-line

With the proxy settings information, you can use the --proxy command-line option to specify a proxy in the form [user:passwd@]proxy.server:port. For example, if you want to install requests package. You can do it using the following command line.

pip --proxy http://some-proxy-ip.com:8087 install requests

Use config file

Instead of typing out the --proxy option every time you run pip, you can set the proxy settings in the pip configuration file. The location of this file vary slightly for different platforms.

  • For MS Windows, the configuration is located at %APPDATA%\pip\pip.ini.
  • For MacOS, the configuration is located at $HOME/Library/Application Support/pip/pip.conf.
  • For Unix, the configuration is located at $HOME/.config/pip/pip.conf.

If path doesn't exist, create it.

In your config file, set the followings.

[global]
proxy = http://some-proxy-ip.com:8087

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.