简体   繁体   English

安装 Pillow with Poetry 后无法导入 PIL

[英]Can't import PIL after installing Pillow with Poetry

I'm trying to install and use Pillow with Python 3.9.2 (managed with pyenv).我正在尝试通过 Python 3.9.2(使用 pyenv 管理)安装和使用 Pillow。 I'm using Poetry to manage my virtual environments and dependencies, so I ran poetry add pillow , which successfully added Pillow = "^8.2.0" to my pyproject.toml.我正在使用 Poetry 来管理我的虚拟环境和依赖项,所以我运行了poetry add pillow ,它成功地将Pillow = "^8.2.0"添加到我的 pyproject.toml 中。 Per the Pillow docs, I added from PIL import Image in my script, but when I try to run it, I get:根据 Pillow 文档,我在我的脚本中添加了from PIL import Image ,但是当我尝试运行它时,我得到:

File "<long/path/to/file.py>", line 3, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

When I look in the venv Poetry is creating for me, I can see a PIL directory ( /long/path/lib/python3.9/site-packages/PIL/ ) and an Image.py file inside it.当我查看 venv Poetry 正在为我创建时,我可以看到一个 PIL 目录 ( /long/path/lib/python3.9/site-packages/PIL/ ) 和其中的一个 Image.py 文件。

What am I missing here?我在这里错过了什么? I've tried:我试过了:

  • Downcasing to from pil import Image per this ;根据这个缩小到from pil import Image did not work不工作
  • Downgrading to lower versions of Python and PIL;降级到 Python 和 PIL 的低版本; works, but defeats the purpose有效,但达不到目的
  • ETA: Exporting a requirements.txt file from Poetry, creating a virtualenv with venv, and installing the packages manually; ETA:从 Poetry 导出一个 requirements.txt 文件,用 venv 创建一个 virtualenv,然后手动安装包; works, but cuts me off from using Poetry/pyproject.toml有效,但使我无法使用 Poetry/pyproject.toml

Any help would be tremendously appreciated.任何帮助将不胜感激。

I couldn't find a way to solve this either (using poetry 1.1.13).我也找不到解决这个问题的方法(使用诗歌 1.1.13)。

Ultimately, I resorted to a workaround of poetry add pillow && pip install pillow so I could move on with my life.最终,我求助于poetry add pillow && pip install pillow的解决方法,这样我就可以继续我的生活了。 :P :P

poetry add pillow gets the dependency in to the TOML, so consumers of the package should be OK. poetry add pillow获取 TOML 的依赖关系,因此 package 的消费者应该没问题。

capitalizing "Pillow" solved it for me:大写“枕头”为我解决了这个问题:

poetry add Pillow

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

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