How do I install a Python package with a .whl file?
Asked Answered
B

19

1251

I'm having trouble installing a Python package on my Windows machine, and would like to install it with Christoph Gohlke's Window binaries. (Which, to my experience, alleviated much of the fuss for many other package installations). However, only .whl files are available.

http://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype

But how do I install .whl files?

Notes

  • I've found documents on wheel, but they don't seem so staightforward in explaining how to install .whl files.
  • This question is a duplicate with this question, which wasn't directly answered.
Badalona answered 11/1, 2015 at 8:48 Comment(7)
See pip.pypa.io/en/latest/user_guide.html#installing-from-wheelsDiscontinue
What prompted this move from exe to whl anyway? Usually people try to make things easier to use rather than harder.Zsazsa
@Zsazsa the boon compared to .exe's is that publishers only have to upload one wheel (usually) to support all Python versions. You're right though, wheels are less easy for people trying to install packages. It would be neat if you could double click the .whl files.Lubricant
Possible duplicate of How do I install Python libraries?Convert
@Discontinue you link says one needs to install a wheel package, divenex below says, one does not. Who is right?Bekelja
pip install ... does not require the wheel package; pip wheel ... does.Discontinue
Installing from WheelsTrimerous
Z
1475

I just used the following which was quite simple. First open a console then cd to where you've downloaded your file like some-package.whl and use

pip install some-package.whl

Note: if pip.exe is not recognized, you may find it in the "Scripts" directory from where python has been installed. If pip is not installed, this page can help: How do I install pip on Windows?

Note: for clarification
If you copy the *.whl file to your local drive (ex. C:\some-dir\some-file.whl) use the following command line parameters --

pip install C:/some-dir/some-file.whl
Zamir answered 12/1, 2015 at 19:12 Comment(14)
You do not need pip install wheel. The command pip install some-package.whl is sufficient. Only make sure pip is updated, as stated by burhan-khalid.Surovy
Also, you should open the command prompt as administrator in order to run pip in windowsTrueblood
python -m pip install some-package.whl also works if pip is not found in PATH.Dashpot
add c:\python27\scripts to path so use pipNich
Installing a Python module in an offline setting is infuriating. No pip obviously. OK so there's a setup.py... But it doesn't work? Oh it requires setuptools. Wonderful. Okay install setuptools - what's this, .whl? Oh, that requires pip! Feels like I'm stuck in a loop.Kevakevan
For python 3 I've been using pip3 instead of pip (I had 2.7 and now have 3.4). Anyway, this is a friendly reminder that sometimes pip3 is what you need.Fiftieth
@Kevakevan if using setup.py with wheels then you do need wheel installed.Dickie
Try to disconnect your network, then install your wheel. Almost times you will get error. Offline installing only works for the standalone packages.Highams
How cann I call / use it in my class? @DashpotHeliotropin
How we can solve this error: ERROR: grpcio-1.33.2-cp38-cp38-win32.whl is not a supported wheel on this platform. WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.Algorithm
One more thing : Do not rename the wheel file or else pip will refuse to install it. Because pip uses the file name to detect package and architecture info.Varden
@MrAlexander does running the cmd as Admin make sure the package is installed into the system Python installation? (instead of the user directory)Paine
This answer no longer works as of python 3.12.Crazyweed
For those of us who found this Q/A without regard to the OS and are using a Mac, you should use "pip3" as MacOS has 2.7 installed and cannot be removed. This might change in releases after 11.x ... assuming your development work uses Py3.Halie
B
89

First, make sure you have updated pip to enable wheel support:

pip install --upgrade pip

Then, to install from wheel, give it the directory where the wheel is downloaded. For example, to install package_name.whl:

pip install --use-wheel --no-index --find-links=/where/its/downloaded package_name
Bulla answered 11/1, 2015 at 9:14 Comment(6)
What is "wheel"?Doorstone
Use without --use-wheel in pip 19.0.1 (python 2.7)Hurling
@PeterMortensen the package format, what whl is an abbreviation forDickie
Could you please show the difference between the two commands in this answer and in the top answer?Hardunn
@PeterMortensen: Exactly! I don't understand why every person has to give some strange name for an installer. In Fedora there's yum. In Ubuntu there's apt-get and snap. In Mac it's brew. All these wise-cracks could have just named it install.Subjacent
@Subjacent Heh... install is already the name of a tool; man page.Orris
O
26

There's a slight difference between accessing the .whl file in python2 and python3. In python3, you need to install wheel first and then you can access .whl files.

Python3

pip install package.whl

OR

pip install wheel

And then by using wheel

wheel unpack some-package.whl

Python2

pip install some-package.whl
Od answered 20/10, 2020 at 18:6 Comment(2)
but unpack just unpacks the content, doesn't seem to install itGarrity
@ItamarKatz you can directly install by using command pip install package.whl.Od
J
25

I am in the same boat as the OP.

Using a Windows command prompt, from directory:

C:\Python34\Scripts>
pip install wheel

seemed to work.

Changing directory to where the whl was located, it just tells me 'pip is not recognized'. Going back to C:\Python34\Scripts>, then using the full command above to provide the 'where/its/downloaded' location, it says Requirement 'scikit_image-...-win32.whl' looks like a filename, but the filename does not exist.

So I dropped a copy of the .whl in Python34/Scripts, ran the exact same command over again (with the --find-links= still going to the other folder), and this time it worked.

Jazminejazz answered 26/1, 2015 at 20:2 Comment(4)
@EinarSundgren I disagree, he listed all steps that led him to solve op's problem.Bagby
To avoid having to stand in the C:\Python34\Scripts directory when running pip, add that directory to the system path instead. For those who don't know how: windowsitpro.com/systems-management/…Pelham
An extra example, after opening the command prompt, I just pasted in this and hit enter. Nothing else required: C:\Python34\python.exe -m pip install requests It automatically downloaded the 'requests' package and installed it.Hustle
This last comment worked perfectly for me. Could be posted as an answer !Wiggly
M
25

There are several file versions on the great Christoph Gohlke's site.

Something I have found important when installing wheels from this site is to first run this from the Python console:

import pip
print(pip.pep425tags.get_supported())

so that you know which version you should install for your computer. Picking the wrong version may fail the installing of the package (especially if you don't use the right CPython tag, for example, cp27).

Marrowbone answered 5/6, 2015 at 17:43 Comment(2)
Thank you, was having trouble finding this info! However, I'm not sure how to read the output to determine which version I need.Soot
Gohlke's wheel repository is going to shut down soon :(Heterosis
K
16

You have to run pip.exe from the command prompt on my computer. I type C:/Python27/Scripts/pip2.exe install numpy

Koski answered 23/2, 2015 at 14:53 Comment(2)
I have no Scripts directory. Does pip not come with a regular install?Konstanze
@jozxyqk: no. Look here for installation instructions: pip.pypa.io/en/latest/installing.htmlPelham
A
14

On Windows you can't just upgrade using pip install --upgrade pip, because the pip.exe is in use and there would be an error replacing it. Instead, you should upgrade pip like this:

easy_install --upgrade pip

Then check the pip version:

pip --version

If it shows 6.x series, there is wheel support.

Only then, you can install a wheel package like this:

pip install your-package.whl
Ania answered 27/4, 2015 at 3:17 Comment(4)
I just upgraded pip on Windows 7 using pip install --upgrade pip and it worked fine—so that part of what you say appears to be incorrect.Destructible
Perhaps the pip guys realize this and solve the problem in newer versions...I don't know. At least when the answer was posted (in early-2015) I did encountered the error.Ania
You're probably right. Actually, most of the time, pip tells me there's a newer version of it available and offers to upgrade itself, so I seldom do it manually.Destructible
Running Python 3.5.2 on Windows 10, "python -m pip install --upgrade pip" just successfully upgraded pip-8.1.1 to pip-8.1.2Brandi
P
11

To be able to install wheel files with a simple doubleclick on them you can do one the following:

1) Run two commands in command line under administrator privileges:

assoc .whl=pythonwheel
ftype pythonwheel=cmd /c pip.exe install "%1" ^& pause

2) Alternatively, they can be copied into a wheel.bat file and executed with 'Run as administrator' checkbox in the properties.

PS pip.exe is assumed to be in the PATH.

Update:

(1) Those can be combined in one line:

assoc .whl=pythonwheel& ftype pythonwheel=cmd /c pip.exe install -U "%1" ^& pause

(2) Syntax for .bat files is slightly different:

assoc .whl=pythonwheel& ftype pythonwheel=cmd /c pip.exe install -U "%%1" ^& pause

Also its output can be made more verbose:

@assoc .whl=pythonwheel|| echo Run me with administrator rights! && pause && exit 1
@ftype pythonwheel=cmd /c pip.exe install -U "%%1" ^& pause || echo Installation error && pause && exit 1
@echo Installation successfull & pause

see my blog post for details.

Palomino answered 13/11, 2015 at 12:11 Comment(3)
Useful! Thank you, axil & Anthony. Presumably, to avoid dependence on the Scripts folder being in the path, you could use: cmd /c python -m pip install "%1" & pauseBrandi
Well, I was wrong. You've got to use pip.exe. However, one other issue is that if you use the ftype command as shown, the "pause" will run at the command prompt, rather than getting stored in the registry as part of the file association. You'll need to run regedit to add the "& pause" in the shell command in the registry. (Just search the registry for pythonwheel.)Brandi
@DaveBurton I've fixed and updated my answer. Thank you.Palomino
R
6

EDIT: THIS NO LONGER IS A PART OF PIP

To avoid having to download such files, you can try:

pip install --use-wheel pillow

For more information, see this.

Riorsson answered 3/6, 2016 at 8:52 Comment(2)
make sure to have installed the latest version of pip before via python -m pip install --upgrade pipRiorsson
the use-wheel option no longer works and that website doesn't exist and is replaced by some chinese siteArlyn
C
6

In-case if you unable to install specific package directly using PIP.

You can download a specific .whl (wheel) package from - https://www.lfd.uci.edu/~gohlke/pythonlibs/

CD (Change directory) to that downloaded package and install it manually by -
pip install PACKAGENAME.whl
ex:
pip install ad3‑2.1‑cp27‑cp27m‑win32.whl

Carsoncarstensz answered 8/2, 2018 at 10:55 Comment(1)
Gohlke's wheel repository is going to shut down soon :(Heterosis
P
5

You can install the .whl file, using pip install filename. Though to use it in this form, it should be in the same directory as your command line, otherwise specify the complete filename, along with its address like pip install C:\Some\PAth\filename.

Also make sure the .whl file is of the same platform as you are using, do a python -V to find out which version of Python you are running and if it is win32 or 64, install the correct version according to it.

Petry answered 2/1, 2017 at 5:28 Comment(0)
V
4

The only way I managed to install NumPy was as follows:

I downloaded NumPy from here https://pypi.python.org/pypi/numpy

This Module

https://pypi.python.org/packages/d7/3c/d8b473b517062cc700575889d79e7444c9b54c6072a22189d1831d2fbbce/numpy-1.11.2-cp35-none-win32.whl#md5=e485e06907826af5e1fc88608d0629a2

Command execution from Python's installation path in PowerShell

PS C:\Program Files (x86)\Python35-32> .\python -m pip install C:/Users/MyUsername/Documents/Programs/Python/numpy-1.11.2-cp35-none-win32.whl
Processing c:\users\MyUsername\documents\programs\numpy-1.11.2-cp35-none-win32.whl
Installing collected packages: numpy
Successfully installed numpy-1.11.2
PS C:\Program Files (x86)\Python35-32>

PS.: I installed it on Windows 10.

Valene answered 9/11, 2016 at 12:34 Comment(0)
E
4

New Python users on Windows often forget to add Python's \Scripts directory to the PATH variable during the installation. I recommend to use the Python launcher and execute pip as a script with the -m switch. Then you can install the wheels for a specific Python version (if more than one are installed) and the Scripts directory doesn't have to be in the PATH. So open the command line, navigate (with the cd command) to the folder where the .whl file is located and enter:

py -3.6 -m pip install your_whl_file.whl

Replace 3.6 by your Python version or just enter -3 if the desired Python version appears first in the PATH. And with an active virtual environment: py -m pip install your_whl_file.whl.

Of course you can also install packages from PyPI in this way, e.g.

py -3.6 -m pip install pygame
Ecumenicist answered 11/3, 2017 at 21:49 Comment(0)
S
4

On the MacOS, with pip installed via MacPorts into the MacPorts python2.7, I had to use @Dunes solution:

sudo python -m pip install some-package.whl

Where python was replaced by the MacPorts python in my case, which is python2.7 or python3.5 for me.

The -m option is "Run library module as script" according to the manpage.

(I had previously run sudo port install py27-pip py27-wheel to install pip and wheel into my python 2.7 installation first.)

Sassaby answered 9/3, 2018 at 1:25 Comment(0)
C
4

I would be suggesting you the exact way how to install .whl file. Initially I faced many issues but then I solved it, Here is my trick to install .whl files.

Follow The Steps properly in order to get a module imported

  1. Make sure your .whl file is kept in the python 2.7/3.6/3.7/.. folder. Initially when you download the .whl file the file is kept in downloaded folder, my suggestion is to change the folder. It makes it easier to install the file.
  2. Open command prompt and open the folder where you have kept the file by entering

cd c:\python 3.7

3.Now, enter the command written below

>py -3.7(version name) -m pip install (file name).whl
  1. Click enter and make sure you enter the version you are currently using with correct file name.

  2. Once you press enter, wait for few minutes and the file will be installed and you will be able to import the particular module.

  3. In order to check if the module is installed successfully, import the module in idle and check it.

Thank you:)

Cyrenaica answered 27/12, 2018 at 12:18 Comment(0)
S
3

What I did was first updating the pip by using the command: pip install --upgrade pip and then I also installed wheel by using command: pip install wheel and then it worked perfectly Fine.

Hope it works for you I guess.

Slinkman answered 22/3, 2018 at 14:50 Comment(0)
P
3

Download the package (.whl).

Put the file inside the script folder of python directory

C:\Python36\Scripts

Use the command prompt to install the package.

C:\Python36\Scripts>pip install package_name.whl
Plante answered 16/11, 2019 at 9:32 Comment(0)
A
3

Theoretically:

Because wheel is a built distribution spec ie, no dependency on a build system and because it's a ZIP-format archive, it just has to be unpacked to the target location in-order to be used.

While pip install *.wheel adds extra features, we can also unzip (using a standard archive tool eg: 7zip) the .whl file into site-packages directory to use the package.

https://packaging.python.org/specifications/binary-distribution-format/

Athena answered 26/10, 2021 at 10:58 Comment(0)
L
3

I resolved this in next steps:

  1. Download (for macBook M1 in my case) lxml-4.9.2-cp311-cp311-macosx_10_15_universal2.whl from https://github.com/lxml/lxml/releases/tag/lxml-4.9.2
  2. saved it on desktop to folder
  3. open terminal and wrote path to this folder
  4. then on terminal enter: pip install <downloaded_wheel_filename_with_extension>
Larrigan answered 22/3, 2023 at 22:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.