How to install PIL with pip on Mac OS?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The original PIL project is no longer maintained, so installing PIL directly with pip usually fails on modern macOS. The supported replacement is Pillow, which provides a compatible import path through from PIL import .... A reliable installation on Mac depends on matching Python environment, pip binary, and native library dependencies.
Use Pillow Instead of Legacy PIL
If you run pip install PIL, pip will not find a current package. Use Pillow and keep the PIL import namespace in your code.
Verify the install:
This command should print a Pillow version and exit without errors.
Install in a Virtual Environment
On macOS, using a virtual environment avoids conflicts with system Python and Homebrew Python packages.
Then run a quick smoke test.
If sample.png appears, installation and basic image operations are working.
Handle Native Dependency Issues on macOS
Some Pillow features depend on libraries such as libjpeg, zlib, and freetype. If wheel resolution fails and pip tries source build, install common dependencies with Homebrew first.
Then reinstall Pillow in the active environment:
Most users get prebuilt wheels, but this fallback helps on unusual architectures or pinned older versions.
Confirm Correct Python and pip Pairing
A frequent macOS issue is installing packages with one interpreter and running code with another. Always pair pip with the exact interpreter using python -m pip.
If your editor uses a different interpreter, select the same virtual environment there too.
Migrate Old PIL Code Safely
Many old codebases already import PIL. In most cases, only installation changes are required. API names are largely compatible, but check release notes when upgrading across large version gaps.
This code works with Pillow and keeps legacy import style intact.
Troubleshoot Build and Import Errors
If installation succeeds but imports fail, inspect the active interpreter path and site packages location. This quickly reveals whether your shell and editor are using different Python runtimes.
For reproducible team setups, pin Pillow in a requirements file:
Pinned versions reduce surprise upgrades that may change image codec behavior across developer machines.
Common Pitfalls
A common mistake is running pip install PIL and assuming package mirrors are broken. The project is simply deprecated and replaced by Pillow.
Another issue is installing Pillow globally, then running code inside a virtual environment that does not have it. Verify active environment before installation.
A third issue is architecture mismatch on Apple Silicon, where terminal runs one Python build and editor runs another. Keep one consistent interpreter path.
Summary
- Install Pillow, not legacy PIL, on modern macOS.
- Use
python -m pipso pip matches the runtime interpreter. - Prefer virtual environments for stable package isolation.
- Install native dependencies only if wheel installation fails.
- Validate with a short script that creates and saves an image.
- Treat Pillow as the maintained drop-in replacement and avoid chasing the old PIL package name.
Related reading
- How to install pip with Python 3?
- how to install pip with yum on EC2
- How to install psycopg2 with pip on Python?
- How to install python3 version of package via pip on Ubuntu?
- How to install Python 3.8 along with Python 3.9 in Arch Linux?
- How to install python modules without root access?
- How to install Python MySQLdb module using pip?
- How to install Python MySQLdb module using pip?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.