You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu下Manim运行报错:无法从PIL导入_imaging的解决咨询

Fixing ImportError: cannot import name '_imaging' from 'PIL' in Manim (Ubuntu + Python3.7)

Hey there, let's work through this PIL/Pillow issue you're facing with Manim. I've run into similar dependency quirks before, so here's a step-by-step breakdown to get you back up and running:

First, correct the import mistake in camera.py

You mentioned changing the import to from pillow import Image—that's the wrong module name! Pillow is a drop-in replacement for PIL, but you still import it using PIL as the module name. Revert that line in camera.py back to:

from PIL import Image

Step 1: Ensure Pillow is installed for your specific Python 3.7 environment

It's common to have multiple Python versions on Ubuntu, so even if pip says Pillow is installed, it might be linked to a different Python version. Let's explicitly target Python 3.7:

  1. Uninstall any existing Pillow installations tied to Python 3.7:
    python3.7 -m pip uninstall -y Pillow
    
  2. Install a Pillow version that's fully compatible with Python 3.7 (v8.4.0 is a reliable choice):
    python3.7 -m pip install Pillow==8.4.0
    

Step 2: Fix missing system dependencies (if installation was incomplete)

Sometimes Pillow fails to compile its native extensions (like _imaging) on Ubuntu because of missing system libraries. Install the required dev packages first:

sudo apt-get update && sudo apt-get install python3.7-dev libjpeg-dev zlib1g-dev

Then reinstall Pillow with no cache to ensure a fresh build:

python3.7 -m pip install Pillow==8.4.0 --no-cache-dir

Step 3: Verify the fix works

Test if PIL imports correctly in your Python 3.7 environment:

python3.7 -c "from PIL import Image; print(f'Pillow version: {Image.__version__}')"

If this prints the version number without errors, you're good to go. Now try running your Manim command again:

python3.7 -m manim example_scenes.py SquareToCircle -pl

Bonus check: Virtual environment sanity

If you're using a virtual environment for Manim, make sure you activate it before running any pip or python3.7 commands. A common mistake is installing packages in the global environment while using a virtual one.

内容的提问来源于stack exchange,提问作者soutrik das

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 19:52:40