Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does "pip install" build a wheel?

Tags:

python

pip

I found that in different folders, sometimes pip install will build wheel which takes a lot of time, while sometimes it doesn't. I'm not sure why and how to control that.

My command: bin/python -m pip install -r ../requirements.txt (due to the !# shebang line-length limitation, so I don't use pip directly)

The output without building a wheel (just takes a few seconds):

Collecting numpy==1.10.4 (from -r ../requirements.txt (line 1))
Installing collected packages: numpy
Successfully installed numpy-1.10.4

The output with building wheel (take at least 2 minutes)

Collecting numpy==1.10.4 (from -r ../requirements.txt (line 1))
  Downloading numpy-1.10.4.tar.gz (4.1MB)
    100% |████████████████████████████████| 4.1MB 92kB/s
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy ... done
  Stored in directory: /root/.cache/pip/wheels/66/f5/d7/f6ddd78b61037fcb51a3e32c9cd276e292343cdd62d5384efd
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.10.4

The contents of requirements.txt:

numpy==1.10.4
like image 361
zjffdu Avatar asked Feb 03 '16 06:02

zjffdu


People also ask

Should I pip install wheel?

It's not required, but it's recommended. Pip will work just fine without wheels, but you'll be installing from source ( tar. gz , . zip or .

How do you make a pip wheel?

Go to your command prompt/ conda prompt from where you can run python and pip commands, if not sure then check this link. Change directory in the command prompt and navigate to your project root directory where setup.py is placed . Execute python setup.py bdist_wheel . Voila!

Why does pip install build wheel?

According to the Python Packaging Authority (PyPA), wheels are the preferred way that pip installs Python modules from the Python Package Index (PyPI) because they're smaller, faster to install, and more efficient than building the package from the source code contained in an sdist.


3 Answers

Today I encountered a problem where a package wasn't being installed properly because it turns out that its build process generates incorrect wheel packages, even though direct installation works just fine.

I did a bit of poking around, and it turns out that as of now (pip == 8.1.2), there isn't a direct way to control whether or not pip will try to build a wheel out of a given package. I found the relevant source code, and apparently, the wheel build process is used if and only if:

  • the wheel module is importable
  • a cache directory is in use

As a result of that logic, one can indirectly disable pip's use of wheel-based builds by passing --no-cache-dir on the install command line.

like image 96
Simon Ruggier Avatar answered Oct 24 '22 03:10

Simon Ruggier


This depends on whether your package is a pure python package (without the need to compile anything, just copy the files somewhere) or a package which also includes c source code (in which case a compilation is necessary and a compiler is called and executed, which takes longer).

http://pythonwheels.com/

You may also want to have a look at the wheel docu:

http://wheel.readthedocs.org/en/latest/

like image 8
tfv Avatar answered Oct 24 '22 03:10

tfv


I got the answer, it is just the first time that the wheel will be build, after that, it will read from cache

like image 4
zjffdu Avatar answered Oct 24 '22 05:10

zjffdu