Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does pip download .whl files?

Tags:

python

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.

like image 394
elzell Avatar asked Jan 18 '18 17:01

elzell


2 Answers

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, or by setting environment variables; see the Using a Proxy Server section in the Pip User Guide.

like image 138
Martijn Pieters Avatar answered Nov 11 '22 11:11

Martijn Pieters


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"])
like image 7
Marat Avatar answered Nov 11 '22 12:11

Marat