我正试图在工作中通过代理使用pip。

这篇文章中的一个答案建议使用CNTLM。我安装和配置它根据这另一个帖子,但运行cntlm.exe -c cntlm.ini -I -M http://google.com给出错误连接到代理失败,退出。

我还尝试了pip install——proxy=user:pass@localhost:3128(默认的CNTLM端口),但会引发无法获取索引基础URL http://pypi.python.org/simple/。很明显代理出问题了。

有人知道如何更明确地检查CNTLM是否设置正确,或者是否有另一种方法完全绕过这个问题吗?我知道你也可以像这里描述的那样设置http_proxy环境变量,但我不确定要放入什么凭证。来自cntlm.ini的那些?


当前回答

Windows 7系统:

pip install --proxy DOMAIN\user:password@proxyaddress:port package

例如:

pip install --proxy BR\neo:p4ssw0rd@myproxyrocks.com.br:8080 virtualenv

其他回答

设置如下环境变量:export PIP_PROXY=http://web-proxy.mydomain.com

我得到了错误:

chris@green:~$ sudo http_proxy=http://localhost:3128 pip install django==1.8.8 
Downloading/unpacking django==1.8.8
  Cannot fetch index base URL http://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement django==1.8.8
No distributions at all found for django==1.8.8
Storing complete log in /home/chris/.pip/pip.log

(代理服务器的端口是ssh端口转发到localhost:3128)。

我必须同时设置http和https代理使其工作:

chris@green:~$ sudo http_proxy=http://localhost:3128 https_proxy=http://localhost:3128 pip install django==1.8.8
Downloading/unpacking django==1.8.8
  Downloading Django-1.8.8.tar.gz (7.3Mb): 7.3Mb downloaded
  Running setup.py egg_info for package django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
  Running setup.py install for django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of build/scripts-2.7/django-admin.py from 644 to 755
    changing mode of /usr/local/bin/django-admin.py to 755
    Installing django-admin script to /usr/local/bin
Successfully installed django
Cleaning up...

http://pypi.python.org/simple/重定向到https://pypi.python.org/simple,但pip的错误没有告诉你。

如果是windows,请到C:/ProgramData/pip/pip.ini,然后设置

(全球)

proxy = http://YouKnowTheRest

与您的代理详细信息。这将永久地为pip配置代理。

windows 2022年:

我知道有很多答案,几乎所有其他关于pip和代理的问题都指向这个问题:

所以在我看来,一方面是代理的问题,这在下面的问题中得到了回答。

PIP install——proxy=https://<windowsuser>:<pw>@<proxy>:端口包

在此之后,您必须处理SSL证书。您必须添加可信源。通常它们会出现在错误消息中。例如:ERROR: ....下面是我安装Django的解决方案:

pip install Django——proxy http://windowsuser:password@proxy:port——truste- host pypi.python.org——truste- host pypi.org——truste- host files.pythonhosted.org

这对我不起作用。我不得不在工作中使用https:

pip install --proxy=https://user@mydomain:port somepackage

为了更新,添加-U。