How to set an HTTP proxy in Python 2.7?

前端 未结 6 443
無奈伤痛
無奈伤痛 2020-11-29 18:38

I am trying to run a script that installs pip: get-pip.py and am getting a connection timeout due to my network being behind an HTTP proxy. Is there some way I could configu

6条回答
  •  长情又很酷
    2020-11-29 19:03

    It looks like get-pip.py has been updated to use the environment variables http_proxy and https_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
    

    However if this still doesn't work for you, you can always install pip through a proxy using setuptools' easy_install by setting the same environment variables.

    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
    

    Then once it's installed, use:

    pip install --proxy="user:password@server:port" packagename
    

    From the pip man page:

    --proxy
    Have pip use a proxy server to access sites. This can be specified using "user:password@proxy.server:port" notation. If the password is left out, pip will ask for it.

提交回复
热议问题