Using pip behind a proxy

2018-12-31 15:16发布

I am trying to use pip behind a proxy at work.

One of the answers from this post suggested using CNTLM. I installed and configured it per this other post, but running cntlm.exe -c cntlm.ini -I -M http://google.com gave the error Connection to proxy failed, bailing out.

I also tried pip install -–proxy=user:pass@localhost:3128 (the default CNTLM port) but that raised Cannot fetch index base URL http://pypi.python.org/simple/. Clearly something's up with the proxy.

Does anyone know how to check more definitively whether CNTLM is set up right, or if there's another way around this altogether? I know you can also set the http_proxy environment variable as described here but I'm not sure what credentials to put in. The ones from cntlm.ini?

标签: python proxy pip
26条回答
看风景的人
2楼-- · 2018-12-31 15:47

With Ubuntu I could not get the proxy option to work as advertised – so following command did not work:

sudo pip --proxy http://web-proxy.mydomain.com install somepackage

But exporting the https_proxy environment variable (note its https_proxy not http_proxy) did the trick:

export https_proxy=http://web-proxy.mydomain.com

then

sudo -E pip install somepackage
查看更多
临风纵饮
3楼-- · 2018-12-31 15:47

This worked for me (on Windows via CMD):

pip install --proxy proxyserver:port requests
查看更多
心情的温度
4楼-- · 2018-12-31 15:47

I solved the problem with PIP in Windows using "Fiddler" (https://www.telerik.com/download/fiddler). After downloading and installing, do the following:

"Rules" => click "Automatically Authenticate"

Example: pip install virtualenv -proxy 127.0.0.1:8888

Just open your prompt and use.

https://github.com/pypa/pip/issues/1182 Search for "voltagex" (commented on 22 May 2015)

查看更多
人间绝色
5楼-- · 2018-12-31 15:48

Phone as mobile hotspot/USB tethering

If I have much trouble finding a way through the corporate proxy, I connect to the web through my phone (wireless hotspot if I have wifi, USB tether if not) and do a quick pip install.

Might not work for all setups, but should get most people by in a pinch.

查看更多
闭嘴吧你
6楼-- · 2018-12-31 15:48

For windows users: if you want to install Flask-MongoAlchemy then use the following code

pip install Flask-MongoAlchemy --proxy="http://example.com:port"**
查看更多
爱死公子算了
7楼-- · 2018-12-31 15:48

for windows go to C:/ProgramData/pip/pip.ini, and set

[global]

proxy = http://YouKnowTheRest

with your proxy details. This permanently configures the proxy for pip.

查看更多
登录 后发表回答