pip install using proxy in a virtual environment
Asked Answered
K

4

8

I work on a Ubuntu VM in my company's laptop which uses proxy server for connecting to internet. After some research I found out how to install modules using pip install with proxy. For example, using this command I can install my virtualenv module:

sudo pip install --proxy=http://user:pass@<proxy_address>:<portnumber> virtualenv

However, after creating a virtual environment folder, activate it and then install a module using this pip command:

pip install --proxy=http://user:pass@<proxy_address>:<portnumber> pyperclip

I get this error:

 Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/pyperclip/

If I use sudo, pip can download and install the module, but in system global package instead of in my virtual environment. It seems for me a permission issues in my Ubuntu and its proxy setting.

How can I tackle this issue, so that I can install a module locally in my virtualenv?

Thanks

Krummhorn answered 17/6, 2016 at 9:25 Comment(1)
Possible duplicate of Proxy awareness with pipGentlemanfarmer
K
8

Meanwhile, I know the solution. pip needs the environment variable HTTP_PROXY and HTTPS_PROXY in capital letters, instead of http_proxy. So append below text pattern at the end of your your '~/.bashrc'

HTTP_PROXY=http://username:pass@proxyaddress:port
export HTTP_PROXY
HTTPS_PROXY=http://username:pass@proxyaddress:port
export HTTPS_PROXY

Then, run source ~/.bashrc Now you can install all python packages using pip in your Ubuntu VM with proxy login.

Krummhorn answered 29/8, 2016 at 14:16 Comment(3)
Does not work inside my corporate proxy. I get the below error - Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required',))': /simple/rasa-core/Frei
Which Ubuntu version do you use? Another solution for Ubuntu 16.04 is to append the proxy entries in the file "/etc/apt/apt.conf.d/70debconf". Acquire::http::Proxy "http://username:pass@proxyadress:portnumber"; Acquire::https::Proxy "https://username:pass@proxyadress:portnumber";Krummhorn
Thanks. I am now using CNTLM to bypass my company proxy.Frei
R
2

Do not activate the virtualenv and run your pip install --proxy ... command with the full path to your virtualenv pip i.e.

C:\Users\name\myvenv\Scripts\pip install --proxy=http://user:pass@<proxy_address>:<portnumber> virtualenv

Reproachful answered 1/3, 2019 at 18:21 Comment(1)
this did the trick for me when VS Code was trying to search for extensions after setting up virtual environments.Subirrigate
T
0

You might need to exit out of virtualenv and install packages offline. Download packages with:

pip download -d <path/to/downloads/> {package_name | -r requirements.txt}

Then enter your virtualenv, install packages with:

pip install {package_name| -r requiements.txt} --no-index --find-links <path/to/downloads/>
Tsaritsyn answered 30/4, 2021 at 13:0 Comment(0)
A
0

Do not activate the virtualenv and run your pip instl --proxy ... command with the full path to your virtualenv pip i.e.

C:\Users\name\myvenv\Scripts\pip install --proxy=http://user:pass@<proxy_address>: virtualenv

Ashaashamed answered 4/12, 2023 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.