我正试图在工作中通过代理使用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的那些?


当前回答

我也遇到了同样的问题:在一个带有认证的公司代理的背后,我无法进行pip工作,以及Sublime Text 2(好吧,它可以自定义设置我的代理设置)。 对于pip(我将在git上尝试),我解决了安装cntlm代理。 配置起来非常简单:

编辑cntlm.ini 编辑“用户名”、“域”、“密码”字段 添加一个“代理”行,使用您的代理设置:服务器:端口 确保行“NoProxy”集成了“localhost”(默认情况下就像这样) 注意默认端口:3128 保存,就是这样。

为了测试它的工作,只需启动一个新的命令行工具,并尝试:

pip install django --proxy=localhost:3128

这对我很管用。 希望这对你有所帮助。

其他回答

我也不是这方面的专家,但我通过在~/中设置all_proxy变量使其工作。bashrc文件。(打开~/。Bashrc文件和编辑它从终端运行以下命令,

gedit ~/.bashrc &

在文件末尾添加以下内容,

export all_proxy="http://x.y.z.w:port"

然后要么打开一个新终端,要么在同一个终端上运行following,

source ~/.bashrc

仅仅设置http_proxy和https_proxy变量对于简单使用pip install somepackage是不够的。虽然sudo -E pip install somepackage可以工作,但这给我带来了一些问题,以防我在用户文件夹中使用Anaconda的本地安装。

附注:我使用的是Ubuntu 16.04。

安装PIP:

ex:PORT = 9090
ex:PROXY_SERVER = stackoverflow
USERNAME:your user id
PASSWORD: your password

sudo pip2 install PACKAGENAME——proxy https://USERNAME:PASSWORD@PROXY_SERVER:PORT/ for Python2.7

sudo pip3 install PACKAGENAME——proxy https://USERNAME:PASSWORD@PROXY_SERVER:PORT/ for Python3.5

例子:

sudo pip2 install pandas --proxy https://USERNAME:PASSWORD@PROXY_SERVER:PORT/

对于apt-get安装

sudo http_proxy=http://USERNAME:PASSWORD@PROXY_SERVER:PORT/ apt-get install PACKAGENAME

例子:

sudo http_proxy=http://USERNAME:YOURPASSWORD@PROXY_SERVER:PORT/ apt-get install tensorrt

sudo http_proxy=http://USERNAME:YOURPASSWORD@PROXY_SERVER:PORT/ apt-get update

在Windows下不要忘记设置

SET HTTPS_PROXY=<proxyHost>:<proxyPort>

我需要设置什么

pip install pep8

我得到了错误:

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上通过CMD):

pip install --proxy proxyserver:port requests