Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip install using proxy in a virtual environment

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

like image 967
ywiyogo Avatar asked Jun 17 '16 09:06

ywiyogo


People also ask

How do I pass a proxy to pip?

pip can be configured to connect through a proxy server in various ways: using the --proxy command-line option to specify a proxy in the form scheme://[user:passwd@]proxy.server:port. using proxy in a Configuration Files. by setting the standard environment-variables http_proxy , https_proxy and no_proxy .

How do you pass a proxy in Python?

To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.


2 Answers

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.

like image 189
ywiyogo Avatar answered Nov 11 '22 01:11

ywiyogo


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

like image 31
Srian Avatar answered Nov 11 '22 00:11

Srian