How to Use pip with Proxies

Set up proxies with pip to bypass restrictions, improve security, and streamline package management.
11 min read
How to Use Pip with Proxies blog image

In this article, you’ll learn how to configure and use proxies with pip for seamless package management in restricted networks.

Differences Between Public and Private Proxies

When selecting a proxy, determining if it will be public or private is an important consideration.

Public Proxies

Public proxies are open for anyone to use and often lack authentication. While they can provide quick access to an IP address, they come with downsides—slower speeds, unstable connections, and potential IP bans. Because they are free and widely available, they often lack essential features like proxy rotations, caching, and access control, making them unreliable in a production environment.

A public URL may be formatted like this: https://proxyserver:port.

Private Proxies

Private proxies require authentication, offering greater security, stability, and advanced features—though typically at a cost. They offer a secure, fast, and reliable connection to a dedicated IP address, along with features like proxy authentication and rotation.

Access is usually controlled through authentication often by including a username and password as a prefix to the proxy URL like this: https://username:password@proxyserver:port.

Using Proxies with pip

To start using a proxy with pip, you need to gather some details about your proxy. The next example uses a public proxy with the following details:

  • proxy address for the proxy service
  • The port the proxy service requires for communication

The following proxy-list repo provides daily tested public proxy addresses that can be useful for testing but should not be used in production environments.

Within the proxy-list repo, check the proxy-list-status.txt file to find a working public proxy. This can be done by checking the file for an address that has the success flag next to it, indicating that it is working:

Selecting a public proxy

For this tutorial, use 45.185.162.203:999 as your public proxy address. This means the proxy server address is http://45.185.162.203:999.

Configuring a pip Proxy with the Command Line

The quickest way you can configure a pip proxy is to pass in the address when calling the pip install command using the --proxy command line option.

Using the public proxy address, test your access to the proxy and packages using the following command:

# Public Proxy
pip install boto3 --proxy http://45.185.162.203:999

This method is helpful to quickly test and validate proxies before permanently configuring a new proxy. If publishing pip packages, it helps verify availability from a different IP.

Configuring a pip Proxy with the pip Config File

To permanently configure a pip proxy, the pip config file is an easy and declarative solution. Its location depends on your operating system and can be found in the following directories:

  • Global: System-wide configuration file, shared across users.
  • User: Per-user configuration file for the user executing the pip process.
  • Site: Per-environment configuration file using Python virtual environments.

These configuration files can be found or created in the following locations for each system:

Linux/macOS

On Linux-based systems, the pip config file is called pip.conf and can be found in the following locations:

  • Global:
    • Debian-based systems: Edit or create pip.conf in the/etc` directory.
    • macOS-based systems: Edit or create /Library/Application Support/pip/pip.conf.
  • User:
    • Debian-based systems: Edit or create the ~/pip/pip.conf file.
    • macOS-based systems: Edit or create the ~/.config/pip/pip.conf config file.
  • Site: When loaded in a Python virtual environment, it’s located at $VIRTUAL_ENV/pip.conf.

Windows

On a Windows system, the file is a pip.ini file and can be found in the following locations:

  • Global: Edit or create the C:\ProgramData\pip\pip.ini file. Note that this file is hidden by default on Windows systems but is writable.
  • User: Edit or create pip.ini in %APPDATA%\pip\.
  • Site: When loaded in a Python virtual environment, edit or create the config file at %VIRTUAL_ENV%\pip.ini.

Config File Contents

For this example, a Python virtual environment pip config file is used. In an activated virtual environment, edit $VIRTUAL_ENV/pip.conf on Debian-based systems or %VIRTUAL_ENV%\pip.ini on Windows.

In the config file, you need to update the proxy key with your desired HTTP or HTTPS proxy:

[global]
proxy = http://45.185.162.203:999

Once the file is saved, the proxy is used automatically with any pip command, eliminating the need for the proxy flag mentioned previously:

(venv) $ pip install boto3

You can find more details on the configuration options available in the pip config file in the project’s documentation.

Configuring a pip Proxy with Environment Variables

Setting system environment variables ensures that a proxy is used for pip and all other HTTP requests on a system. This is done by utilizing both the HTTP_PROXY and HTTPS_PROXY environment variables, which are often referenced by software like pip as a system proxy to use when making HTTP requests.

Linux/macOS

If you’re using a Linux operating system, update the /etc/environment file, or if you’re a macOS user, update the .zshrc file located in the home directory. Then, update it with new entries for your proxy server:

HTTP_PROXY=https://proxyserver:port
HTTPS_PROXY=https://proxyserver:port

Once you restart your terminal sessions or restart your system, the environment variables will be present.

Windows

On a Windows system, you can set environment variables with the following commands in a command prompt terminal:

setx HTTP_PROXY "https://proxyserver:port" /M
setx HTTPS_PROXY "https://proxyserver:port" /M

Restart the command prompt for the changes to take effect.

Testing the Configuration

Once you have a system-level configuration enabled either through the pip config file or environment variables, you should test that the proxy can successfully connect and receive data via the proxy.

Linux/macOS

On Linux/macOS, use the following command:

$ python -m venv venv
$ source venve/scripts/activate

# for pip config file or environment variables
(venv) $ pip install requests

If you ever want to override these settings with a specific proxy, you can fall back on using the CLI flags:

# pip cli flag
(venv) $ pip install requests --proxy https://proxyserver:port

In this command, make sure you update https://proxyserver:port with your own proxy.

Windows

On Windows, use the following command:

> python -m venv venv
> .\venv\Scripts\Activate.bat
(venv) > pip install requests

These settings can always be overridden using the pip CLI flags:

# pip cli flag
(venv) $ pip install requests --proxy https://proxyserver:port

Troubleshooting pip Proxies

When connecting to an HTTP or HTTPS proxy with pip, you may come across the following common issues, particularly if you explore using private proxies or HTTPS proxies due to their enhanced features.

Authentication Issues

Authentication issues are commonly seen as a 407 Proxy Authentication Required error when trying to connect to the proxy with pip. This indicates that the proxy requires a username and password to connect or you have provided the wrong credentials for the proxy.

Certificate Issues

When connecting to an HTTPS proxy, you may receive a Certificate verify failed error from pip. This indicates that there is an issue with the certificate provided by the proxy server.

If your private proxy server is using a self-signed certificate, you may get this error, and the certificate cannot be verified with a certificate authority. You may want to use the --trusted-host CLI option when connecting to certain domains and ignore self-signed certificate errors.

Using pip with Rotating Proxies

Rotating proxies help avoid IP bans by automatically switching IP addresses for each request. This mimics multiple users and bypasses restrictions.

You can implement this by randomly selecting proxies from a list. Below is a simple bash script that installs pip packages while rotating through public proxies.

Create the following bash script called rotate-proxies.sh:

proxy_list=(
  'http://45.185.162.203:999'
  'http://177.23.176.58:8080'
  'http://83.143.24.66:80'
)

pip_packages=(
  'requests'
  'numpy'
  'pandas'
)

# Loop through packages and install them
for package in "${pip_packages[@]}"
do
  # Randomly select a proxy from the list
  proxy=${proxy_list[$RANDOM % ${#proxy_list[@]}]}
  echo -e  "\nInstalling $package with proxy $proxy"
  pip install --proxy $proxy $package
done

Once created, you can then execute the file to download the pip packages and rotate through a random proxy for each pip command. Here’s a summary of the script’s output:

$ ./rotate-proxies.sh

Installing requests with proxy http://177.23.176.58:8080
Collecting requests
  Downloading requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)

….

Downloading urllib3-2.3.0-py3-none-any.whl (128 kB)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests
Successfully installed certifi-2025.1.31 charset-normalizer-3.4.1 idna-3.10 requests-2.32.3 urllib3-2.3.0

Installing six with proxy http://45.185.162.203:999
Collecting numpy
 Downloading numpy-2.2.2-cp313-cp313-macosx_14_0_x86_64.whl.metadata (62 kB)

…

Installing collected packages: numpy
Successfully installed numpy-2.2.2

Installing pandas with proxy http://83.143.24.66:80
Collecting pandas
  Downloading pandas-2.2.3-cp313-cp313-macosx_10_13_x86_64.whl.metadata (89 kB)

….

Installing collected packages: pytz, tzdata, six, python-dateutil, pandas
Successfully installed pandas-2.2.3 python-dateutil-2.9.0.post0 pytz-2025.1 six-1.17.0 tzdata-2025.1

Benefits of Using Proxies with pip

Proxies help developers bypass network restrictions, access blocked resources, and improve package download speeds. Private proxies offer caching, faster connections, and enhanced security by masking your identity.

Compared to a VPN , proxies are a lightweight alternative for pip requests. While a VPN encrypts all internet traffic for broader privacy, it can slow down package installations due to increased latency. Proxies provide a faster, more efficient solution for managing dependencies.

Common Mistakes and Best Practices

When using proxies with pip, it’s important to watch out for common mistakes as they can lead to security vulnerabilities. Errors such as incorrect proxy URLs or misconfigured URL formats—like missing or incorrect HTTP or HTTPS protocol—can disrupt connections to package repositories.

A frequent security issue is hard-coding proxy credentials (eg usernames and passwords) in source codes, scripts, or continuous integration, continuous delivery (CI/CD) pipeline definitions. If this code is redistributed, unauthorized access to the proxy can occur. If credentials are compromised, the proxy may be misused, leading to increased costs or even exploited by cyberattacks.

To avoid these mistakes, it’s recommended that proxy credentials are kept secure by storing them in environment variables or encrypted configuration files rather than directly in code. Additionally, you must test proxy connectivity before using pip to ensure proper setup and avoid runtime errors. Using tools like curl or ping, you can verify proxy performance before putting it into service. This enables a smoother package management experience.

Using Bright Data Proxies

If you’re looking for a provider of high-quality and featured proxies, check out Bright Data. It’s a proxy solution that provides a range of IP addresses, including residential, data centers, and mobile devices. It also provides specialized tools for data collection and web scraping, including rotating proxies and the Web Unlocker API.

Bright Data can help you easily create proxies for your project’s needs. To show you how easy it is, let’s create a private residential proxy that you can use with pip to access packages via a different IP address.

Start by signing up for a free Bright Data account. Then navigate to the user dashboard.

On the side menu, click on Proxies & Scraping:

Bright Data proxies

Once the form has loaded, configure a new residential proxy. If you use the default settings, you’ll get a proxy with a shared IP address used by multiple Bright Data users:

Creating a residential proxy

If you’re targeting a specific region, you can also specify the country in which you want the IP address to be located.

After creation, you are redirected to a dashboard that contains the endpoint and authentication details for your newly created proxy. Take note of both the username, password, and server address:

Proxy dashboard

Using these endpoint values, test their availability using the --proxy flag:

$ pip install pandas \
    --trusted-host pypi.org \
    --trusted-host files.pythonhosted.org \
    --proxy https://username:password@brd.superproxy.io:33335

Because the Bright Data proxy uses a self-signed certificate, you can use the trusted-host flag to whitelist pypi.org and files.pythonhosted.org as trusted domains.

Conclusion

Using a proxy with pip helps enhance anonymity and control, enabling you to bypass IP restrictions and geoblocking. Depending on your needs, you can choose between public and private proxies.

Private proxies offer advantages, like rotating IPs, improved caching, faster speeds, and greater stability, but the cost depends on IP availability and geographic location.

Configuring a proxy for pip is simple, with multiple options like CLI flags, a pip config file, and environment variables. However, public proxies have limitations, and as discussed previously, they aren’t ideal for large workloads or production use. For a more reliable solution, Bright Data offers residential and datacenter IPs, providing fast, stable connections and advanced tools for web scraping and data collection. Sign up for free to get started.

No credit card required