Fin Moorhouse
Fin Moorhouse

Reputation: 335

Cannot use Pillow in my Python project

I recently installed pip, and used that to install Pillow, the Python imaging library, on Ubuntu 14.04. When I write some simple code like the following:

import sys

from PIL import Image

im= Image.open('path/to/image.jpg')
im.save('path/to/image2.jpg')

I get the following error:

Traceback (most recent call last):
File "/path/to/test.py", line 3, in <module>
from PIL import Image
File "/path/to/test.py", line 3, in <module>
from PIL import Image
ImportError: cannot import name Image

I have also tried just 'import Image', but this doesn't work either. I seem to recollect that this vaguely worked once, before I installed Pillow. It seems as though nobody else has this problem, so is there something I'm missing? Many thanks in advance.

Upvotes: 1

Views: 738

Answers (1)

Hugo
Hugo

Reputation: 29314

[Summrising the answer in the comments, for future reference]

Make sure you haven't created a file called PIL.py (or PIL.pyc), as this will interfere with the import.

To check:

import PIL; print(PIL.__file__)

This should give you some path like /foo/bar/site-packages/PIL/__init__.py. and not something like /home/fin/PIL.py.

Upvotes: 1

Related Questions