3

I installed Python 3.7.3 on windows 10, but I can't install Python packages via PIP in Gitbash (Git SCM), due to my company's internet proxy.

I tryed to create environment variables for the proxy via the following, but it didn't work:

  • export http_proxy='proxy.com:8080'
  • export https_proxy='proxy.com:8080'

I found a temporary solution that works for me: inserting the following aliases into the .bashrc file:

  • alias python='winpty python.exe'
  • alias pip='pip --proxy=proxy.com:8080'

The above is working but I am looking for a nicer solution so that I don't need to set aliases for every command I use. I was thinking about something like an environment variable but didn't found out how to set it up on a windows' git bash environment yet.

Do you have an idea on how to do it?

Wes
  • 31
  • 3

2 Answers2

1

First, you don't need Git bash to pip install Python modules.
Only Git path (to use linux-like commands, plus curl, even though it is available on recent Windows 10), from a regular CMD, with a simplified PATH:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
set PH=C:\path\to\Python37
set PATH=%PH%;%PH%\Scripts

Second, you can pip install in a corporate environment, provided:

  • you access your proxy through px, an HTTP proxy server to automatically authenticate through an NTLM proxy
  • you use and trust mirror alternatives for pip module sources.

Regarding genotrance/px, simply run the service with px --proxy=my.company.prpxy:<port> --save --config=/path/to/your/px.ini

No need to enter your credentials (Windows log/password): the proxy uses your current login session.

Set your environment variable to reference that proxy:

set HTTP_PROXY=http://localhost:3128
set HTTPS_PROXY=http://localhost:3128

Then, this will work:

λ pip install -i http://pypi.mirror.frontiernet.net/simple --trusted-host pypi.mirror.frontiernet.net "ansible-tower-cli==3.2.1" --force-reinstall
Looking in indexes: http://pypi.mirror.frontiernet.net/simple
Collecting ansible-tower-cli==3.2.1
  Downloading http://pypi.mirror.frontiernet.net/packages/98/39/566f2dc628917e28d6600607cd0a533b9ed02395297363b2db827e59e488/ansible-tower-cli-3.2.1.tar.gz (153kB)
    100% |████████████████████████████████| 163kB 107kB/s

(Use any pypi mirror not blocked by your company=

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • to avoid a so long `pip install -i xyz --trusted-host xyz` it is possible to use a var env used by pip on windows to inform pip that localhost:3128 is the Web proxy ? – user3313834 Apr 14 '19 at 09:28
  • @user3313834 Yes: I have edited my answer accordingly – VonC Apr 14 '19 at 09:38
0

first you need to check if the corp Proxy you are behind is NTLM or not, check this https://stackoverflow.com/a/12476379/3313834 may help.

user3313834
  • 5,701
  • 4
  • 40
  • 76