Home > Article > Backend Development > Why am I getting \"ImportError: No module named PIL\" even though I\'ve installed PIL?
Troubleshooting "ImportError: No module named PIL"
When attempting to import the Python Imaging Library (PIL) using the command "import PIL," you encounter the error "ImportError: No module named PIL." This occurs despite having apparently installed PIL using "easy_install PIL."
Resolution:
The issue arises because "easy_install" installs PIL as "PIL.py" in Python's site-packages directory. To resolve this:
1. Deprecation Note:
PIL is deprecated and has been succeeded by Pillow. For future installations, it is recommended to use Pillow instead:
pip install Pillow
2. For Existing PIL Installations:
pip install Pillow
Pillow will be installed and provide the necessary compatibility layer to work with PIL.
Attention: If you encounter any issues with this approach, it may be necessary to manually add the PIL.py file to your Python path. However, this is not recommended as Pillow is the preferred and supported library going forward.
The above is the detailed content of Why am I getting \"ImportError: No module named PIL\" even though I\'ve installed PIL?. For more information, please follow other related articles on the PHP Chinese website!