当我使用 pip 安装包时,“Building wheel for xxx”是什么意思?

Bra*_*ble 5 python python-2.7 python-3.x

当我运行命令时pip install allennlp,输出如下所示。是什么意思Building wheel for xxx?背后的动作是 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
Run Code Online (Sandbox Code Playgroud)

查了一下,好像wheel是一种帮助pip设置包的文件,但我还是没有清楚的了解。我知道这个问题可能是一个愚蠢的问题,但知道答案会很好。

Sub*_*han 5

我假设您已经了解了以下方面的文档:

运行pip install allennlpwith-vvv可以提供与您的具体问题相关的更多见解:

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
Run Code Online (Sandbox Code Playgroud)

使这个漂亮的进程运行的 pip 包代码位于github最终它调用 的jsonnetMakefile来“构建”轮子

简而言之,选择 的示例jsonnet,运行pip install jsonnet会执行以下操作:

  • 将 jsonnet.tar.gz 下载到本地临时文件夹
  • 调用c++命令来编译 .cpp 文件
  • 构建_jsonnet.cpython-37m-darwin.so(这是我的 Mac OS 机器的正确库格式)
  • 记录车轮分布信息jsonnet-0.12.1.dist-info(通常存在于您的虚拟环境中)

这个流程是针对 的jsonnet,而且它恰好有点复杂,因为 jsonnet 最终是一个 C 扩展。但是常规的 python 包只会下载源文件并将其安装在 virtualenv 中。您可以沿着相同的路径来了解任何包背后发生的情况。