混淆的一个来源是,当你执行例如
pip install pycparser
时,首先会出现错误:Failed building wheel for pycparser
,然后是包安装成功的消息:Successfully installed pycparser-2.19
。# pip3 install pycparser
Collecting pycparser
Using cached https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz
Building wheels for collected packages: pycparser
Running setup.py bdist_wheel for pycparser ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g_v28hpp/pycparser/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 /tmp/pip-wheel-__w_f6p0 --python-tag cp36:
Traceback (most recent call last):
File "<string>", line 1, in <module>
...
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2349, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'wheel.bdist_wheel'
----------------------------------------
Failed building wheel for pycparser
Running setup.py clean for pycparser
Failed to build pycparser
Installing collected packages: pycparser
Running setup.py install for pycparser ... done
Successfully installed pycparser-2.19
这里发生了什么?
(我希望理解一件事情如何可以失败但仍然被安装,以及你是否可以信任这个软件包的正确功能?)
到目前为止,我找到的最好的部分解释是这个。
pip
找不到满足要求的wheel时,它会下载源代码压缩包并尝试在本地构建一个wheel。构建成功后,wheel将被存储在pip
的缓存中以供未来重新安装使用。如果构建wheel失败,pip
则切换到从源代码压缩包进行传统安装(调用python setup.py install
)。 - hoeflingpip install somepkg --no-binary=somepkg
。或者使用pip install somepkg --no-binary=:all:
,但要注意,这将禁用所有选定的软件包(包括依赖项)的轮,如果某个软件包需要安装的没有源分布,则安装将失败。 - hoefling--no-binary
将指示pip仅下载并使用源分发。防止它构建本地二进制轮子的旗帜确实是--no-cache-dir
。 - Serge Ballesta.tar.gz
文件,它是 PyPI 上的源分发包(wheel 文件将具有.whl
扩展名)。 - Serge Ballesta--no-cache-dir
会隐式禁用wheel构建;这让我感到有些惊讶。我一直以为--no-cache-dir
只是忽略本地缓存目录(读和写都是),所以可以使用它来重建本地wheel而不是使用缓存的wheel。今天学到了新东西! - hoefling