Michael
Michael

Reputation: 61

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). 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. Per the Pillow docs, I added from PIL import Image in my script, but when I try to run it, I get:

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.

What am I missing here? I've tried:

Any help would be tremendously appreciated.

Upvotes: 3

Views: 4535

Answers (2)

Amund
Amund

Reputation: 72

capitalizing "Pillow" solved it for me:

poetry add Pillow

Upvotes: 1

Gordon Bean
Gordon Bean

Reputation: 4612

I couldn't find a way to solve this either (using poetry 1.1.13).

Ultimately, I resorted to a workaround of poetry add pillow && pip install pillow so I could move on with my life. :P

poetry add pillow gets the dependency in to the TOML, so consumers of the package should be OK.

Upvotes: 1

Related Questions