为什么 python setup.py bdist_wheel 创建一个构建文件夹?

Why does python setup.py bdist_wheel creates a build folder?

刚学会上传my own python packages to PyPI thanks to this amazing tutorial. I am trying now to better understand how wheels works and I found this article很有帮助

但是,我仍然不明白为什么 python setup.py bdist_wheel 创建了一个名为 build 的几乎空的目录,其中包含两个子文件夹:bdist.win-amd64(空)和 lib(其中包含我的包的副本),以及 dist 目录中的 .whl 文件,开发人员稍后将通过执行 python -m twine upload dist/*.

上传到 PyPI

为什么需要这个 build 目录?我的意思是, dist 目录还不够吗?此外,如果代码未实际编译,为什么 .whl 称为 二进制分布

python setup.py bdist_wheel internally 运行s python setup.py install which internally 运行s python setup.py build which compiles/builds project into a temporary location inside build/ 目录,然后将编译后的项目安装到 build/ 目录内的另一个临时位置。它从第二个临时位置的文件中创建一个轮子。

至于编译 — python 模块可以用 C/C++ 编写,而且通常是这样。所以python setup.py build需要编译。如果没有要编译的东西——好吧,编译步骤被跳过但构建步骤仍然是 运行.