31

I was looking for a tutorial on how to install Python libraries in the wheel format.

It does not seem straightforward so I'd appreciate a simple step by step tutorial how to install the module named "requests" for CPython.

I downloaded it from: https://pypi.python.org/pypi/requests and now I have a .whl file. I've got Python 2.7 and 3.3 on Windows, so how do I install it so all the other Python scripts I run can use it?

1

11 Answers 11

22

You want to install a downloaded wheel (.whl) file on Python under Windows?

  1. Install pip on your Python(s) on Windows (on Python 3.4+ it is already included)
  2. Upgrade pip if necessary (on the command line)

    pip install -U pip
    
  3. Install a local wheel file using pip (on the command line)

    pip install --no-index --find-links=LocalPathToWheelFile PackageName
    

Option --no-index tells pip to not look on pypi.python.org (which would fail for many packages if you have no compiler installed), --find-links then tells pip where to look for instead. PackageName is the name of the package (numpy, scipy, .. first part or whole of wheel file name). For more informations see the install options of pip.

You can execute these commands in the command prompt when switching to your Scripts folder of your Python installation.

Example:

cd C:\Python27\Scripts
pip install -U pip
pip install --no-index --find-links=LocalPathToWheelFile PackageName

Note: It can still be that the package does not install on Windows because it may contain C/C++ source files which need to be compiled. You would need then to make sure a compiler is installed. Often searching for alternative pre-compiled distributions is the fastest way out.

For example numpy-1.9.2+mkl-cp27-none-win_amd64.whl has PackageName numpy.

2
  • A so billed "Successfully installed pip-6.1.1" didn't work but "pip-Win" overcame that hurdle but could not install numpy (likley no compiler) which I needed. A "numpy superpack" overcame that hurdle. This summary makes it seem easy but it was far from a nice installation experience. May 20, 2015 at 19:51
  • @chip_wrangler You're right. Package installations for Python under Windows can be pain in the ass (no compiler included in the OS by default). Often pre-compiled packages are the easiest way out. However I feel this is more the fault of Windows than of Python or any Python tool. May 26, 2015 at 9:49
6

If you want to be relax for installing libraries for python.

You should using pip, that is python installer package.

To install pip:

  1. Download ez_setup.py and then run:

    python ez_setup.py
    
  2. Then download get-pip.py and run:

    python get-pip.py
    
  3. upgrade installed setuptools by pip:

    pip install setuptools --upgrade
    

    If you got this error:

    Wheel installs require setuptools >= 0.8 for dist-info support.
    pip's wheel support requires setuptools >= 0.8 for dist-info support.
    

    Add --no-use-wheel to above cmd:

    pip install setuptools --no-use-wheel --upgrade
    

Now, you can install libraries for python, just by:

pip install library_name

For example:

pip install requests

Note that to install some library may they need to compile, so you need to have compiler.

On windows there is a site for Unofficial Windows Binaries for Python Extension Packages that have huge python packages and complied python packages for windows.

For example to install pip using this site, just download and install setuptools and pip installer from that.

2
  • 4
    The Unofficial Windows Binaries for Python Extension Packages now contains only Python wheel files (.whl) installable using pip install library_name.
    – mcarans
    Jan 26, 2015 at 12:44
  • Using Win7; after step 3 I'm stuck with get-pip.py telling me that pip is installed in whatever directory, but no pip executable to run. Any idea to relieve this definite pain I feel growing in my @ss?
    – kuroi neko
    Jan 29, 2015 at 7:46
2

To install wheel packages in python 2.7x:

  1. Install python 2.7x (i would recommend python 2.78) - download the appropriate python binary for your version of windows . You can download python 2.78 at this site https://www.python.org/download/releases/2.7.8/ -I would recommend installing the graphical Tk module, and including python 2.78 in the windows path (environment variables) during installation.

  2. Install get-pip.py and setuptools Download the installer at https://bootstrap.pypa.io/get-pip.py Double click the above file to run it. It will install pip and setuptools [or update them, if you have an earlier version of either]

-Double click the above file and wait - it will open a black window and print will scroll across the screen as it downloads and installs [or updates] pip and setuptools --->when it finishes the window will close.

  1. Open an elevated command prompt - click on windows start icon, enter cmd in the search field (but do not press enter), then press ctrl+shift+. Click 'yes' when the uac box appears.

A-type cd c:\python27\scripts [or cd \scripts ]

B-type pip install -u Eg to install pyside, type pip install -u pyside

Wait - it will state 'downloading PySide or -->it will download and install the appropriate version of the python package [the one that corresponds to your version of python and windows.]

Note - if you have downloaded the .whl file and saved it locally on your hard drive, type in
pip install --no-index --find-links=localpathtowheelfile packagename

**to install a previously downloaded wheel package you need to type in the following command pip install --no-index --find-links=localpathtowheelfile packagename

1
  • NOTE I posted the above post earlier, mostly in uppercase, because I have an illness which makes it difficult to type. I just wanted to help, but was voted down for the uppercase.Formatting may be off for any number of reasons. Please consider those reasons..it may help someone else.
    – str8arrow
    Mar 21, 2015 at 19:31
1

Have you checked this http://docs.python.org/2/install/ ?

  1. First you have to install the module

    $ pip install requests

  2. Then, before using it you must import it from your program.

    from requests import requests

    Note that your modules must be in the same directory.

  3. Then you can use it.

    For this part you have to check for the documentation.

2
  • 1
    It's worth mentioning that, using only these steps on a windows platform, many modules will simply fail to install if they need access to a compiler or specific library headers Jan 19, 2014 at 20:25
  • In Windows pip doesn't even come with Python older than 3.4. You can install it from e.g. here.
    – Cu3PO42
    Jan 19, 2014 at 21:10
0

Install distribute by downloading and running distribute_setup.py. This will make easy_install available, and from there you can install pip with easy_install pip. Then you can run pip install CAGE. Using pip to install things is a lot easier than messing with manually running setup.py, because pip can do things like:

automatically resolve dependencies
show you a list of all installed packages and their versions
install a set of specified packages from a requirements.txt
upgrade and uninstall packages
work with virtualenv

If you're on Windows, the one downside of pip occurs when there are C library dependencies, as pip will want a C toolchain installed so it can compile things. If that is the case, then there are two options. If there are precompiled binaries on PyPI, then just run easy_install package instead; easy_install knows how to use binary packages. You can also check Christoph Gohlke's site for executable installers of many binary packages. These can also be installed by easy_install if you want to use them with a virtualenv (just point it to the path of the .exe) or you can click and run if you don't care about virtualenv.

The main point is that no matter what route you choose to install packages, at no point are you ever moving around files by hand. You need to get out of the mindset of "I extracted this archive, where do I put these .py files?" That's not how it works. You're either running pip, running easy_install, running setup.py, clicking on an installer package, or using your distribution's installer. At no point are you ever doing anything by hand with the files directly.

1
0

Once you have a library downloaded you can execute this from the MS-DOS command box:

python setup.py install

The setup.py is located inside every library main folder.

1
0

For windows, there are automatic installer packages available at this site

It includes most of the python packages.

But the best way for it is of course using pip.

2
  • 1
    But what if the file from this location is not an installer but a .whl file? Feb 3, 2015 at 13:39
  • Unfortunately, not anymore. Everything is wheels now.
    – joaquin
    Jul 21, 2015 at 19:00
0

You don't need to download exclusively from the website. Just make sure you have pip (which you probably will if you have python installed). Just open your Command Prompt (CMD) and run the command:

pip install pygame

It will automatically download the correct whl version of pygame compatible with your configuration of PC. Make sure you remember the version which appears while "downloading" as this is the compatible version of .whl packages you shall be looking for in the future.

0

Simple steps to install python in Ubuntu:

  1. Download Python

    $ cd /usr/src 
    $ wget  https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
    
  2. Extract the downloaded package

    $ sudo tar xzf Python-3.6.0.tgz
    
  3. Compile Python source

    $ cd Python-3.6.0
    $ sudo ./configure
    $ sudo make altinstall 
    

    Note make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

  4. check the python version

    # python3.6 -V
    
0

i have write the answer here How to add/use libraries in Python (3.5.1) but no problem will rewrite it again

if u have or you can create a file requirements.txt which contains the libraries that you want to install for ex:

numpy==1.14.2
Pillow==5.1.0

You gonna situate in your folder which contains that requirements.txt in my case the path to my project is

C:\Users\LE\Desktop\Projet2_Sig_Exo3\exo 3\k-means

now just type

python -m pip install -r ./requirements.txt

and all the libararies that you want gonna install

C:\Users\LE\Desktop\Projet2_Sig_Exo3\exo 3\k-means>python -m pip install -r ./requirements.txt
0

python 3.4+ onwards command

# python -m ensurepip

output

Looking in links: /tmp/tmpeoq86krb
Requirement already satisfied: setuptools in /usr/lib/python3.9/site-packages (53.0.0)
Processing /tmp/tmpeoq86krb/pip-21.2.3-py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-21.2.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.