Skip to content

Unable to import pillow/PIL #9801

Description

@Ethan-Prunty

Describe the bug

Recently I've been working with pillow/PIL and I've run into a weird behavior. For reference, here is a quick rundown of what my code does:

  1. Import marimo, PIL, and a few other libraries.
  2. Add an image selection area with mo.ui.file.
  3. Run PIL.Image.open on the selected image.

Step 3 is where the first problem occurs. When I run my notebook in a sandboxed environment, it lists pillow in the dependencies, and seems to install it. import PIL does not fail (correction: when pillow is manually removed from the dependencies, marimo offers to install Pillow and pillow. When that dialogue is accepted, PIL does not fail to import, and pillow does fail (more on that in a second)). But when I reach step three, I get an error stating that "module 'PIL' has no attribute 'Image'".

This is where the second strange behavior comes in. To fix the above error, I need to:

  1. Import pillow instead of PIL,
  2. Get an error saying that pillow is not installed (even though it is both in the dependencies list and manually installed,
  3. And finally, import PIL instead of pillow.

Then everything works beautifully!

I suspect that this behavior might have something to do with PIL and pillow technically being different libraries/ the weirdness of how they are related. I have no idea why it offers to install both Pillow and pillow, though. It's not fatal, but it is irritating that I have to go through this process every time I reopen that particular notebook.

Image Image

Will you submit a PR?

  • Yes

Environment

Details
{
  "marimo": "0.23.8",
  "editable": false,
  "location": "C:/Users/user/AppData/Local/Programs/Python/Python314/Lib/site-packages/marimo",
  "OS": "Windows",
  "OS Version": "11",
  "Processor": "Intel64 Family 6 Model 140 Stepping 1, GenuineIntel",
  "Python Version": "3.14.0",
  "Locale": "--",
  "Binaries": {
    "Browser": "148.0.7778.217",
    "Node": "v24.13.0",
    "uv": "0.10.6 (a91bcf268 2026-02-24)"
  },
  "Dependencies": {
    "click": "8.3.0",
    "docutils": "0.22.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.9",
    "narwhals": "2.9.0",
    "packaging": "25.0",
    "psutil": "7.1.2",
    "pygments": "2.19.2",
    "pymdown-extensions": "10.21.3",
    "pyyaml": "6.0.3",
    "starlette": "0.48.0",
    "tomlkit": "0.13.3",
    "typing-extensions": "4.15.0",
    "uvicorn": "0.38.0",
    "websockets": "15.0.1"
  },
  "Optional Dependencies": {
    "loro": "1.10.3",
    "pandas": "2.3.3",
    "python-lsp-server": "1.14.0"
  },
  "Experimental Flags": {}
}

Code to reproduce

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions