Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "Building wheel for xxx" when I use pip install package?

When I running the command pip install allennlp, the output looks below. What is the meaning of Building wheel for xxx? What is the action behind Building wheel for xxx?

Building wheel for jsonnet (setup.py) ... done
  Stored in directory: /Users/xu/Library/Caches/pip/wheels/f0/47/51/a178b15274ed0db775a1ae9c799ce31e511609c3ab75a7dec5
  Building wheel for nltk (setup.py) ... done
  Stored in directory: /Users/xu/Library/Caches/pip/wheels/97/8a/10/d646015f33c525688e91986c4544c68019b19a473cb33d3b55
  Building wheel for parsimonious (setup.py) ... done

I've done some search and it seems wheel is a kind of files that help pip to set up the package, but I still have not a clear understanding. I know this question might be a silly question, it would be good to know the answer though.

like image 670
Bramble Avatar asked May 25 '19 22:05

Bramble


People also ask

What is wheel package used for?

A wheel is a ZIP-format archive with a specially formatted filename and the . whl extension. It is designed to contain all the files for a PEP 376 compatible install in a way that is very close to the on-disk format.

What is a building wheel?

Wheel building is the process of attaching the rim to the hub using spokes and nipples as fasteners, and then bringing the entire structure up to proper tension.

What is a Python build wheel?

A wheel is a built package that can be installed without needing to go through the “build” process. Installing wheels is substantially faster for the end user than installing from a source distribution. If your project is pure Python then you'll be creating a “Pure Python Wheel” (see section below).

What does building wheel mean pip?

If you've installed a Python package using pip , then chances are that a wheel has made the installation faster and more efficient. Wheels are a component of the Python ecosystem that helps to make package installs just work. They allow for faster installations and more stability in the package distribution process.


1 Answers

I am assuming you have already caught up with documentation on:

  • The Wheel Packaging format and what the .whl file contains
  • Building a .whl file
  • Installing from Pypi

Running pip install allennlp with -vvv offers more insights related to your specific question:

Created temporary directory: /private/var/folders/kh/1cpkyp_535jg856yrdnql0rw0000gn/T/pip-install-leyfrduz

...

Created temporary directory: /private/var/folders/kh/1cpkyp_535jg856yrdnql0rw0000gn/T/pip-wheel-s1uhiijv
Building wheel for jsonnet (setup.py) ...   Destination directory: /private/var/folders/kh/1cpkyp_535jg856yrdnql0rw0000gn/T/pip-wheel-s1uhiijv
Running command /Users/subhashb/.pyenv/versions/3.7.2/envs/test-env-dev/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/kh/1cpkyp_535jg856yrdnql0rw0000gn/T/pip-install-leyfrduz/jsonnet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/kh/1cpkyp_535jg856yrdnql0rw0000gn/T/pip-wheel-s1uhiijv --python-tag cp37
running bdist_wheel
running build
running build_ext
c++ -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/desugarer.cpp -o core/desugarer.o
core/desugarer.cpp:406:67: warning: unused parameter 'obj_level' [-Wunused-parameter]
    AST* makeArrayComprehension(ArrayComprehension *ast, unsigned obj_level) {

...

writing manifest file 'jsonnet.egg-info/SOURCES.txt'
Copying jsonnet.egg-info to build/bdist.macosx-10.14-x86_64/wheel/jsonnet-0.12.1-py3.7.egg-info
running install_scripts
adding license file "LICENSE" (matched pattern "LICEN[CS]E*")
creating build/bdist.macosx-10.14-x86_64/wheel/jsonnet-0.12.1.dist-info/WHEEL
creating '/private/var/folders/kh/1cpkyp_535jg856yrdnql0rw0000gn/T/pip-wheel-s1uhiijv/jsonnet-0.12.1-cp37-cp37m-macosx_10_14_x86_64.whl' and adding 'build/bdist.macosx-10.14-x86_64/wheel' to it
adding '_jsonnet.cpython-37m-darwin.so'
adding 'jsonnet-0.12.1.dist-info/LICENSE'
adding 'jsonnet-0.12.1.dist-info/METADATA'
adding 'jsonnet-0.12.1.dist-info/WHEEL'
adding 'jsonnet-0.12.1.dist-info/top_level.txt'
adding 'jsonnet-0.12.1.dist-info/RECORD'
removing build/bdist.macosx-10.14-x86_64/wheel
done

The pip package code that makes this beautiful process run is at github. And it eventually ends up making a call to jsonnet's Makefile to "build" the wheel

In short, picking the example of jsonnet, running pip install jsonnet does the following:

  • downloads the jsonnet.tar.gz to a local temporary folder
  • invokes a c++ command to compile .cpp files
  • builds _jsonnet.cpython-37m-darwin.so (which is the correct library format for my Mac OS machine)
  • records the wheel distribution info in jsonnet-0.12.1.dist-info (typically present in your virtual env)

This flow is for jsonnet, and it happens to be slightly complicated because jsonnet is ultimatly a C extension. But regular python packages will just have the source file(s) downloaded and installed in the virtualenv. You can walk the same path to understand what happens behind any package.

like image 134
Subhash Avatar answered Sep 21 '22 03:09

Subhash