2012-07-30 64 views
61

我想運行一個安裝pip的腳本:get-pip.py,並且由於我的網絡在HTTP代理後面而正在獲取連接超時。有什麼方法可以在我的Python 2.7安裝中配置HTTP代理,以便能夠安裝我想安裝的內容?如何在Python 2.7中設置HTTP代理?

注意:我正在使用Windows。下面是我得到的錯誤:

C:\SetupFiles>python get-pip.py 
Downloading/unpacking pip 
    Cannot fetch index base URL http://pypi.python.org/simple/ 
    Could not find any downloads that satisfy the requirement pip 
No distributions at all found for pip 
+0

Windows,Linux或OSX? – tMC 2012-07-30 17:59:21

+0

我正在使用Windows。 – Rolando 2012-07-30 18:02:06

+0

如何永久設置它? – 2016-04-06 06:33:52

回答

111

它看起來像get-pip.py已更新爲使用環境變量http_proxyhttps_proxy

的Windows:

set http_proxy=http://proxy.myproxy.com 
set https_proxy=https://proxy.myproxy.com 
python get-pip.py 

的Linux/OS X:

export http_proxy=http://proxy.myproxy.com 
export https_proxy=https://proxy.myproxy.com 
sudo -E python get-pip.py 

然而,如果這還不適合你,你可以隨時使用setuptoolseasy_install通過設置安裝通過代理點子相同的環境變量。

的Windows:

set http_proxy=http://proxy.myproxy.com 
set https_proxy=https://proxy.myproxy.com 
easy_install pip 

的Linux/OS X:

export http_proxy=http://proxy.myproxy.com 
export https_proxy=https://proxy.myproxy.com 
sudo -E easy_install pip 

然後,一旦它的安裝,使用:

pip install --proxy="user:[email protected]:port" packagename 

pip man page

--proxy
讓pip使用代理服務器訪問網站。這可以使用「user:[email protected]:port」表示法指定爲 。如果遺漏密碼 ,pip將要求它。

+0

你的答案似乎假設PIP已經安裝,我還沒有成功安裝PIP。指導說運行get-pip.py腳本,但我得到連接超時,這是我遇到的麻煩。 – Rolando 2012-07-30 18:11:42

+0

道歉,請參閱我的編輯。 – 2012-07-30 18:18:13

+0

非常好,謝謝! – Rolando 2012-07-30 18:19:42

8

在我的網絡上,只需設置http_proxy並不適用於我。以下幾點是相關的。

1設置HTTP_PROXY您的用戶,當你執行sudo的不會被保留 - 爲了保護它,這樣做:

sudo -E yourcommand 

我得到了我的安裝首先安裝cntlm本地代理工作。這裏的指令是簡潔:http://www.leg.uct.ac.za/howtos/use-isa-proxies

取而代之的學生數量,你把你的域用戶名

2要使用cntlm本地代理,EXEC:

pip install --proxy localhost:3128 pygments 
+1

問題是針對windows,請重新閱讀問題。 – 2014-10-14 09:45:15

3

您可以安裝pip(或任何其他包)與easy_install幾乎如第一個答案中所述。但是,您也需要一個HTTPS代理。命令的完整序列是:

set http_proxy=http://proxy.myproxy.com 
set https_proxy=http://proxy.myproxy.com 
easy_install pip 

您可能還需要一個端口添加到代理,如http{s}_proxy=http://proxy.myproxy.com:8080

1

對於在代理後面安裝帶有get-pip.py的pip,我按照以下步驟進行操作。我的服務器甚至在跳轉服務器後面。

從跳轉服務器:

ssh -R 18080:proxy-server:8080 my-python-server 

在 「蟒蛇服務器」

export https_proxy=https://localhost:18080 ; export http_proxy=http://localhost:18080 ; export ftp_proxy=$http_proxy 
python get-pip.py 

成功。

0
cd C:\Python34\Scripts 

set HTTP_PROXY= DOMAIN\User_Name:[email protected]_SERVER_NAME_OR_IP:PORT# 

set HTTP_PROXY= DOMAIN\User_Name:[email protected]_SERVER_NAME_OR_IP:PORT# 

pip.exe install PackageName 
相關問題