简体   繁体   English

为什么“from PIL import Image”不起作用,而“from pil import Image”却起作用? (小写的 pil)

[英]Why does "from PIL import Image" not work, but "from pil import Image" does? (lowercase pil)

I've come across this strange error with Pillow, where the import name PIL needs to be all lowercase instead of all uppercase, but I've never seen pil used lowercase anywhere.我在使用 Pillow 时遇到过这个奇怪的错误,其中导入名称PIL需要全部小写而不是全部大写,但我从未见过pil在任何地方都使用小写。 This means that all the python packages and files that I use that import PIL don't work and throw a ModuleNotFoundError: No module named 'PIL' .这意味着我使用的导入PIL的所有 python 包和文件都不起作用并抛出ModuleNotFoundError: No module named 'PIL' However when change "PIL" to "pil", the import works.但是,当将“PIL”更改为“pil”时,导入工作。

Pillow version = 9.0.0枕头版本 = 9.0.0
Python version = 3.9.1 Python 版本 = 3.9.1

I came across this error after trying to install d3dshot package.我在尝试安装 d3dshot package 后遇到了这个错误。 Installing d3dshot using pip threw an error about a missing zlib dependency for Pillow, and I followed this answer to successfully install d3dshot.使用 pip 安装 d3dshot 引发了关于 Pillow 缺少 zlib 依赖项的错误,我按照这个答案成功安装了 d3dshot。 After that, I started encountering this PIL error.之后,我开始遇到这个 PIL 错误。

Several references suggest capitalizing Pillow when installing it via pip, including the official documentation , PyPi , and a lot of related stack overflow posts eg 1 .一些参考资料建议在通过 pip 安装Pillow时使用大写字母,包括官方文档PyPi和许多相关的堆栈溢出帖子, 例如 1

I'd suggest trying Pillow = ">=7.1.2" with a capital P in the pyproject.toml.我建议尝试Pillow = ">=7.1.2"在 pyproject.toml 中使用大写字母 P。

For anyone else with this issue, uninstalling pillow and ensuring it is installed using Pillow might resolve the issue.对于遇到此问题的其他人,卸载pillow并确保使用Pillow安装它可能会解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM