10

I'd like to install a certain python package with pip but because of the proxy I am sitting behind pip cannot connect to the internet.

So my question is: Where does pip look for .whl files in order to download them? Can't I just use my browser (which can connect to the internet just fine) to download the .whl file? Installing the package with the downloaded .whl file would be not a problem then.

elzell
  • 2,028
  • 1
  • 11
  • 24
  • https://pypi.python.org/pypi – Mad Physicist Jan 18 '18 at 17:26
  • Why not just configure your proxy? – Martijn Pieters Jan 18 '18 at 17:27
  • @MartijnPieters It's the proxy of our company network which takes username and password. I've managed to configure it in the past with set HTTP_PROXY="username:password@proxy..." in the windows shell but for some reason this doesn't work anymore. – elzell Jan 18 '18 at 17:30
  • @elzell: `pip --proxy username:password@proxy... install ...` should work. – Martijn Pieters Jan 18 '18 at 17:31
  • @MartijnPieters Unfortunately it doesn't. I guess it's the proxy because only some of the software on my computer which can make an internet connection (e.g. for updates) works when I set the proxy settings correctly - also Firefox only works when I set "Detect proxy settings automatically". That's why I didn't want to struggle with it anymore and look for an easier way. – elzell Jan 18 '18 at 17:36
  • 1
    Why not ask your IT department how to configure the proxy? Pip supports most proxy scenarios, it’s just another HTTPS client. – Martijn Pieters Jan 18 '18 at 17:40
  • @MartijnPieters Sure I will do this, but that means opening a ticket and waiting some days or weeks before I get a reply, so I had hoped for the expertise of Stackoverflow to get a quick solution. – elzell Jan 18 '18 at 17:48

2 Answers2

13

pip searches the Python package index (PyPI), each package lists downloads (including wheels, if there are any) with a direct download link on the page. Package pages have the form of https://pypi.python.org/pypi/<package_name> or https://pypi.python.org/pypi/<package_name>/<version> for specific versions.

If you can only download wheels manually with your browser, it doesn't matter where you put the wheel file. Just install the wheel file directly:

pip install path/to/wheel.whl

However, pip supports downloading over a proxy just fine:

pip --proxy username:password@proxy_server:proxy_port install ...

See the --proxy command line switch documentation. You can add the proxy setting to a pip configuration file so you don't have to set it on the command line each time.

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
2

How to get an URL pip is using to download the file:

  • Get JSON from https://pypi.python.org/pypi/package_name/json
  • parse releases part, select the latest release
  • go through available files (usually there are more than one), taking your platform into account (e.g. x32 vs x64, Windows or Linux version, installed Python etc)
  • use url property

E.g.:

import requests
package = requests.get("https://pypi.python.org/pypi/pandas/json").json()
max_ver = max(package["releases"].keys())
# ... check compatibility
file = get_file_idx(package['releases'][max_ver])
urllib.urlretrieve(file["url"])
Marat
  • 10,338
  • 2
  • 30
  • 40
  • Showing the `requests` path is all very well, but rather pointless when the OP is having issues configuring a proxy, don't you think? A *human* would just go to the package page, not the JSON URL. – Martijn Pieters Jan 18 '18 at 17:43
  • @MartijnPieters I understand this is not the answer to the original question, but I imagine this snippet might come in handy in a similar situation – Marat Jan 18 '18 at 17:53