Like it!

Join us on Facebook!

Like it!

Install Python modules with Pip behind a proxy

What to do when a proxy server steps on your toes?

I'm working on Debian Stretch with pip 1.5.6. I need to install a new Python module (Requests, the famous http library) but, being behind a nasty proxy, I can't get pip to work properly. This is the error I'm getting so far:

Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement requests
Cleaning up...
No distributions at all found for requests
Storing debug log for failure in /root/.pip/pip.log

Exporting https_proxy environment variables as I did in one of my previous articles didn't help. Eventually I found a nice and simple solution: the --proxy parameter for pip. Use it as follows:

sudo pip --proxy <proxy> install <module>

For example, if the proxy is http://proxy.hell:3128 and the module you want to install is requests:

sudo pip --proxy http://proxy.hell:3128 install requests

The same solution applies to pip3 as well.

comments
Rohit Anand on January 04, 2019 at 17:24
But this method installs the package in my base python instead of installing it in the virtual environment. How can I fix it??
Triangles on January 05, 2019 at 12:19
@Rohit no clues. What about this? https://packaging.python.org/guides/installing-using-pip-and-virtualenv/
Raja on April 03, 2019 at 22:10
I get the below error. please advise.
'sudo' is not recognized as an internal or external command,
operable program or batch file.

Am also getting timeout
'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/py2exe/
Triangles on April 04, 2019 at 12:30
@Raja this tutorial is intended for Linux only. You're running the command on Windows - "is not recognized as an internal or external command" is a typical Windows terminal message.
himanshu on October 29, 2019 at 07:00
got an error like this can anybody help?
ERROR: Could not install packages due to an EnvironmentError: Failed to parse: https://genproxy:8080
Shresth on November 05, 2019 at 15:08
I'm unable to install any package in a server,
I have used the following command for installation of package:
Say for example:
sudo pip3 install --proxy=proxy.honeywell.com:8080 pyodbc
sudo yum install --proxy=proxy.honeywell.com:8080 python3-pip
Triangles on November 08, 2019 at 11:13
@himanshu looks like there's something missing e.g. an environment variable not set somewhere, maybe?
Pernath on November 07, 2022 at 22:56
Alright I get it, but what if I'm working in a restricted enviroment that calls pip (for example a buildout) and i have no control over the arguments it is being called with.