Most of the time, installing Python packages only takes one line of code. But that simple command might not work right away if you’re behind a company firewall, a school network, or a limited internet connection.
This guide will teach you how to use proxies with pip, why setting up a proxy is important, and how to install Python packages even on networks that aren’t open to everyone.
What Is pip and Why Proxy Configuration Matters
pip is Python’s default package manager. It’s the tool you use to download and install libraries like requests, numpy, or pandas.
When you run a command like:
pip install requests
pip uses the internet to access PyPI (Python Package Index) where it downloads the package and installs it on your system. Pip does not need any additional configuration on open networks, but on limited networks, the connection is frequently blocked.
Most companies and schools restrict open access to software tools on the internet. Instead, all connections must go through a proxy server. If pip is not told to use that proxy, it cannot reach PyPI, and the installation fails.
By setting up a proxy, pip can access the internet. Pip sends its requests through the proxy server, which then sends them to PyPI, instead of connecting to it directly. Even on highly restricted networks, package installation proceeds normally once this route is properly configured.
Common Scenarios Where pip Requires a Proxy
Pip will need a proxy because it won’t be able to access the internet directly. Usually, this happens on small networks.
- Business networks – Direct downloads are prohibited in most workplaces. Pip requires a proxy to access PyPI.
- School or university networks – Pip might not be able to download packages, as school networks usually have limitations on the use of the internet.
- Strict servers – There are servers that block outgoing connections unless they go through a proxy.
- Firewall environments – Pip can be blocked by internal systems that have firewalls unless proxy access is provided.
- Monitored or filtered networks – Use of pip and other tools will often require a proxy on networks that have a monitoring or controlling policy.

How pip Connects to PyPI (Quick Technical Overview)
When you use pip install, pip will be connected to the Python Package Index (PyPI), the primary online repository of Python packages. It makes a secure HTTPS request to request the package and version you specified. PyPI replies with the package files, which are downloaded and installed by pip on your system.
This is a process that requires internet. On limited networks, that direct connection can be blocked, and this is the reason why a regular install fails.
Pip does not communicate with PyPI directly, but sends its request to a proxy server, which then forwards the request to PyPI and sends back the response. This additional step enables pip to download and install packages even on networks with restrictive access policies.
Installing Python Packages with pip Using a Proxy Server
The main goal is to be sure that pip sends its download requests via a proxy instead of attempting to connect to PyPI directly when installing Python packages on a restricted network. You don’t need any additional tools or plugins because pip supports proxy usage.
There are three techniques for doing this. You can store the proxy settings in a pip configuration file for long-term use, set the proxy as an environment variable on your system, or enter the proxy details directly in the pip command. Depending on whether you need a permanent pip install with proxy configuration or a one-time setup, each approach functions differently.
Method 1: Using a Proxy Directly in the pip Command
This is the fastest way to use a proxy with pip. You add the proxy details directly to the pip install command, and pip uses that proxy only for that single install.
This method is useful when you:
- Need a quick test
- Don’t want to change system settings
- Are using a temporary proxy
Basic syntax
pip install package_name –proxy http://proxy_address:port
Example
pip install requests –proxy http://127.0.0.1:8080
If your proxy requires authentication, include the username and password in the proxy URL:
pip install requests –proxy http://username:password@proxy_address:port
Method 2: Setting Proxy Environment Variables
This technique tells your operating system to use a proxy for all internet traffic, including pip. It is not necessary to add proxy details to each pip command once the variables are set.
This method works well when:
- You frequently install packages
- You are looking for a system-wide fix.
- You don’t want to constantly change the proxy settings.
Before sending a network request, pip verifies the environment variables on your system. When pip connects to PyPI, proxy variables are automatically used if they are set.
Setting proxy variables on Linux and macOS
export HTTP_PROXY=http://proxy_address:port
export HTTPS_PROXY=http://proxy_address:port
If authentication is required:
export HTTP_PROXY=http://username:password@proxy_address:port
export HTTPS_PROXY=http://username:password@proxy_address:port
Setting proxy variables on Windows (Command Prompt)
set HTTP_PROXY=http://proxy_address:port
set HTTPS_PROXY=http://proxy_address:port
With authentication:
set HTTP_PROXY=http://username:password@proxy_address:port
set HTTPS_PROXY=http://username:password@proxy_address:port
Method 3: Configuring Proxy in pip Configuration Files
When you want to set up a permanent proxy for pip, this approach is best. Once set up, pip will always use the proxy – no environment variables and no command flags are required.
Your operating system decides the location of the configuration file that pip uses to read its settings.
Where the pip config file is located
On Linux and macOS, the file is usually:
~/.config/pip/pip.conf
On Windows, the file is usually:
%APPDATA%\pip\pip.ini
If the file does not exist, you can create it manually.
Example configuration
Inside the config file, add the following lines:
[global]
proxy = http://proxy_address:port
If your proxy requires authentication:
[global]
proxy = http://username:password@proxy_address:port
