How to use pip on windows behind an authenticating proxy

240,160

Solution 1

I have tried 2 options which both work on my company's NTLM authenticated proxy. Option 1 is to use --proxy http://user:pass@proxyAddress:proxyPort

If you are still having trouble I would suggest installing a proxy authentication service (I use CNTLM) and pointing pip at it ie something like --proxy http://localhost:3128

Solution 2

It took me a couple hours to figure this out but I finally got it to work using CNTLM and afterwards got it to work with just a pip config file. Here is how I got it work with the pip config file...

Solution:

1. In Windows navigate to your user profile directory (Ex. C:\Users\Sync) and create a folder named "pip"

2. Create a file named "pip.ini" in this directory (Ex. C:\Users\Sync\pip\pip.ini) and enter the following into it:

    [global]
    trusted-host = pypi.python.org
                   pypi.org
                   files.pythonhosted.org
    proxy = http://[domain name]%5C[username]:[password]@[proxy address]:[proxy port]

Replace [domain name], [username], [password], [proxy address] and [proxy port] with your own information.

Note, if your [domain name], [username] or [password] has special characters, you have to percent-encode | encode them.

3. At this point I was able to run "pip install" without any issues.

Hopefully this works for others too!

P.S.: This may pose a security concern because of having your password stored in plain text. If this is an issue, consider setting up CNTLM using this article (allows using hashed password instead of plain text). Afterwards set proxy = 127.0.0.1:3128in the "pip.ini" file mentioned above.

Solution 3

This is how I set it up:

  1. Open the command prompt(CMD) as administrator.
  2. Export the proxy settings :

    set http_proxy=http://username:password@proxyAddress:port

    set https_proxy=https://username:password@proxyAddress:port

  3. Install the package you want to install:

    pip install PackageName

For example:

Example

Solution 4

I ran into the same issue on windows 7. I managed to get it working by creating a "pip" folder with a "pip.ini" file inside it. I put this folder inside "C:\Users\{my.username}\AppData\Roaming", because according to the Python documentation:

On Windows the configuration file is %APPDATA%\pip\pip.ini

In the pip.ini file I have only:

[global]
proxy = [proxy address]:[proxy port]

So no username:password. And it is working just fine.

Solution 5

I had a similar issue, and found that my company uses NTLM proxy authentication. If you see this error in your pip.log, this is probably the issue:

Could not fetch URL http://pypi.python.org/simple/pyreadline: HTTP Error 407: Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )

NTLMaps can be used to interface with the NTLM proxy server by becoming an intermediate proxy.

Download NTLMAPs, update the included server.cfg, run the main.py file, then point pip's proxy setting to 127.0.0.1:.

I also needed to change these default values in the server.cfg file to:

LM_PART:1
NT_PART:1

# Highly experimental option. See research.txt for details.
# LM - 06820000
# NT - 05820000
# LM + NT - 
NTLM_FLAGS: 07820000

http://ntlmaps.sourceforge.net/

Share:
240,160
aquavitae
Author by

aquavitae

Updated on December 16, 2020

Comments

  • aquavitae
    aquavitae over 3 years

    My computer is running windows behind a proxy on a windows server (using active directory), and I can't figure out how to get through it with pip (in python3). I have tried using --proxy, but it still just timeouts. I have also tried setting a long timeout (60s), but that made no difference. My proxy settings are correct, and I compared them with those that I'm using successfully in TortoiseHG to make sure.

    Are there any other tricks that anyone knows of that I can try, or is there some limitation in pip with regards to windows proxies?

    Update: My failed attempts involved searching pypi. I've just tried actually installing something and it worked. Searching still fails though. Does this indicate a bug in pip or do they work differently?

  • Michał Fita
    Michał Fita over 11 years
    CNTLM tool is actively maintained and seem to work really well.
  • imbr
    imbr over 9 years
    I could not make it work not matter all tentatives I did
  • Mahesha999
    Mahesha999 over 7 years
    More about pip.ini location can be found here. You can set PIP_CONFIG_FILE environment variable to point to the pip.ini file
  • Arockia
    Arockia over 7 years
    If you have special characters in your password or username, just escape it with \ before the special character. It works fine.
  • hmrc87
    hmrc87 over 7 years
    In my case this only works if I put my username and password in cleartext in this file... :/ Why is everyhting else from the CMD working like "ping XYZ". Why isn't pip using the IE settings?
  • Amith Chinthaka
    Amith Chinthaka over 6 years
    Sometime you might required https proxy also
  • CustodianOfCode
    CustodianOfCode over 6 years
    Legend! This works for me using python 3.6 on windows 7, with pip3
  • randomsock
    randomsock over 6 years
    This is definitely the first thing to try. Python is cross-platform, and this is the equivalent of what we normally do on Linux. Had problems on Windows (behind the same proxy) where the --proxy argument just would not have it at all, but the standard env var approach worked first time. For the record, we also set no_proxy to avoid other internal requests trying to go out through the proxy.
  • avgvstvs
    avgvstvs about 6 years
    Love it!!!! so clean--just remember most proxies will let you manually enter your password. NEVER leave your password in cleartext!
  • TingQian LI
    TingQian LI about 6 years
    Another very important global setting can be added here is mirror site, for example, add "index-url = pypi.tuna.tsinghua.edu.cn/simple" would increase pip download speed a lot in PRC China. And the corresponding file under Linux is ~/.pip/pip.conf
  • Alex B
    Alex B almost 6 years
    what is [domain name]?
  • Robert
    Robert about 5 years
    do I understand this correctly that you are telling pip to send the request to the proxy, authenticating itself with the given user and password via an http connection? That means your password will be sent unencrypted to the proxy server, right!? Looks like a big security risk to me or am I missing something?
  • Mike Pennington
    Mike Pennington about 5 years
    @AlexB, [domain name] refers to your windows domain name
  • Raúl Salinas-Monteagudo
    Raúl Salinas-Monteagudo about 5 years
    It worked for me with a Microsoft Forefront firewall
  • bucky
    bucky almost 5 years
    does not work for me on win10. use a emulator console tool like cygwin or cmder and then do it the linux way: export http_proxy=<proxy> and export https_proxy=<proxy> and then just do pip install <package>
  • mrtexaz
    mrtexaz almost 5 years
    under Windows 10, with authenticating proxy, this works for me: using cntlm as intermediate proxy, then on msdos prompt: "set https_proxy=localhost:3128" and then "pip install -U setuptools==41.0.1"
  • AmbroseChapel
    AmbroseChapel over 4 years
    This worked for me but the --proxy command-line flag never did. Windows 10.
  • Admin
    Admin over 4 years
    It is strange that this is not working for me. I am using windows 10 and if I check my PC Automatic proxy setup, I see "Script address = proxy-europe.network.mycorporate.com"; there is no Address or port# is filled. How can I use this proxy to make my pip work please? I used "pip install --proxy=proxy-europe.network.mycorporate.com pandas" but not working :(
  • Thomas
    Thomas about 4 years
    Is there also a way to prompt for the password instead of typing it in the command? I really don't like to have my password as plain text in my command history.
  • Jari Turkia
    Jari Turkia almost 3 years
    In Windows 10, I don't think using a proxy without HTTPS can be done without Cygwin. No matter what I try, there is always an error about SSL-version. That's obvious as my proxy isn't using SSL.