Python Pip 不在防火墙后面工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21468550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pip not working behind firewall
提问by Bean Taxi
I am trying to use pip from behind a corporate firewall, and not having any luck.
我正在尝试从公司防火墙后面使用 pip,但没有任何运气。
I have set the http_proxyand https_proxyenvironment variables. wget works, but not pip.
我已经设置http_proxy和https_proxy环境变量。wget 有效,但 pip 无效。
I tried this ...
我试过这个...
sudo -E pip install virtualenv
with these proxies ...
使用这些代理...
export http_proxy=myproxyname.mydomain.com:8080
export https_proxy=myproxyname.mydomain.com:8080
... and got a long stacktrace which ended with this
...并得到了一个很长的堆栈跟踪,并以此结束
/requests/packages/urllib3/poolmanager.py", line 214, in __init__
'Not supported proxy scheme %s' % self.proxy.scheme
AssertionError: Not supported proxy scheme None
I looked at the poolmanager.py source. It looks like it is requiring the proxy variables to begin with a scheme. So I tried again with the following proxies ...
我查看了 poolmanager.py 源代码。看起来它要求代理变量以一个方案开始。所以我再次尝试使用以下代理...
export http_proxy=http://myproxyname.mydomain.com:8080
export https_proxy=https://myproxyname.mydomain.com:8080 (also tried this with http://)
... and I get the following error
...我收到以下错误
Downloading/unpacking virtualenv
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement virtualenv
Cleaning up...
No distributions at all found for virtualenv
Storing debug log for failure in /root/.pip/pip.log
This is the same error I get when I do not have a proxy at all, though I get it much faster when the proxies are set.
这与我根本没有代理时得到的错误相同,尽管在设置代理时我得到的速度要快得多。
When I try wget ...
当我尝试 wget ...
wget --no-check-certificate https://pypi.python.org/simple/
It works fine, so I think the proxies themselves seem ok, unless I try them with pip.
它工作正常,所以我认为代理本身看起来不错,除非我用 pip 尝试它们。
Using the --proxyoption instead of envvars did not help. Same results.
使用该--proxy选项而不是 envvars 没有帮助。结果一样。
Any ideas?
有任何想法吗?
Thanks, Bean
谢谢,豆
回答by Odi
piphas an option to set the proxy, so the following should work for you:
pip有一个设置代理的选项,所以以下应该适合你:
sudo -E pip install --proxy="myproxyname.mydomain.com:8080" virtualenv
回答by Roberto
Try adding "http://" before the proxy hostname:
尝试在代理主机名前添加“http://”:
sudo -E pip install --proxy="http://myproxyname.mydomain.com:8080" virtualenv
回答by Joram
This worked for me
这对我有用
export HTTP_PROXY=http://myusr:[email protected]:8080
export HTTPS_PROXY=https://myusr:[email protected]:8080
sudo -E pip3 install --proxy http://myusr:[email protected]:8080 virtualenv
回答by Damian
I had to set all this in Windows to make it work.
我必须在 Windows 中设置所有这些才能使其正常工作。
set http_proxy=http://proxy.corp.com:8083
set https_proxy=http://proxy.corp.com:8083
set all_proxy=http://proxy.corp.com:8083
set no_proxy=localhost,.corp.com
set HTTP_PROXY=http://proxy.corp.com:8083
set HTTPS_PROXY=http://proxy.corp.com:8083
set ALL_PROXY=http://proxy.corp.com:8083
set NO_PROXY=localhost,.corp.com
set PATH=c:\python27\scripts;c:\python27\;%PATH%
Please replace proxy.corp.com:8083with your http proxy server.
请将proxy.corp.com:8083替换为您的 http 代理服务器。
After that I use pip install numpy
之后我使用pip install numpy
[Last ".corp.com" was missing a period (fixed it).... by the way, after MUCH hair-pulling from behind our corporate firewall, THIS solution was the only one that worked!]
[最后一个“.corp.com”缺少一个句点(已修复)......顺便说一下,在我们公司防火墙后面做了很多事情之后,这个解决方案是唯一有效的解决方案!]
回答by user3398996
Use the --trusted-host argument.
使用 --trusted-host 参数。
I figured out how to get it to work with me behind my corporate firewall using the --trusted-host argument.
我想出了如何使用 --trusted-host 参数让它在我的公司防火墙后面与我一起工作。
My first attempt was this:
我的第一次尝试是这样的:
pip install matplotlib
and the failed text was this:
失败的文字是这样的:
Could not fetch URL https://pypi.python.org/simple/matplotlib/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645) - skipping
无法获取 URL https://pypi.python.org/simple/matplotlib/:确认 ssl 证书时出现问题:[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:645) - 跳过
So then I tried this which worked:
然后我尝试了这个工作:
pip3.5 install matplotlib --trusted-host pypi.python.org
pip3.5 install matplotlib --trusted-host pypi.python.org
回答by Sasanka
this is working behind a proxy
这是在代理后面工作
sudo -E pip --proxy username:password@http://IP:portinstall
sudo -E pip --proxy 用户名:密码@ http://IP:portinstall
回答by Caterina De Franco
On windows go to "Internet Properties" ---> "Connection" ---> "LAN Settings"and check the address (if it is a wpad.dat file, download it and look for "ProxyPort" and "ProxyServer").
在 Windows 上,转到“Internet 属性”--->“连接”--->“LAN 设置”并检查地址(如果它是 wpad.dat 文件,请下载并查找“ProxyPort”和“ProxyServer”) .
Then try:
然后尝试:
pip --proxy http://*user*:*password*@P*roxyServer*:*ProxyPort* install *module*

