在虚拟环境中使用代理进行pip安装 [英] pip install using proxy in a virtual environment

查看:299
本文介绍了在虚拟环境中使用代理进行pip安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在公司笔记本电脑中使用Ubuntu VM进行工作,该笔记本计算机使用代理服务器连接到Internet. 经过一些研究,我发现了如何使用pip install和代理一起安装模块.例如,使用此命令,我可以安装我的virtualenv模块:

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

但是,在创建虚拟环境文件夹后,将其激活,然后使用以下pip命令安装模块:

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

我收到此错误:

 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/

如果我使用sudo,则pip可以下载并安装模块,但使用系统全局软件包而不是在我的虚拟环境中.在我看来,Ubuntu及其代理设置中存在权限问题.

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.

如何解决此问题,以便可以在我的virtualenv中本地安装模块?

How can I tackle this issue, so that I can install a module locally in my virtualenv?

谢谢

推荐答案

同时,我知道解决方案. pip需要使用大写字母的环境变量HTTP_PROXYHTTPS_PROXY而不是http_proxy. 因此,在您的'〜/.bashrc'

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

然后运行source ~/.bashrc 现在,您可以使用pip在具有代理登录名的Ubuntu VM中安装所有python软件包.

Then, run source ~/.bashrc Now you can install all python packages using pip in your Ubuntu VM with proxy login.

这篇关于在虚拟环境中使用代理进行pip安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆