5

I tried to use Python's Image Module on my Mac (new to mac)and I had trouble setting it up. I have Yosemite and some of the posts that I found online didn't work. I ended up installing Homebrew and I finally got PIL on my computer. However, instead of using import image (which I saw people doing it online), I have to use from PIL import image. Is there key difference between import Image and from PIL import Image. It's the first time that I actually use Image module.

One more question, do I actually need to install third party tools like Homebrew and Macports to set up my environment?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Armin
  • 107
  • 1
  • 5
  • Please share some code about the issue. – mertyildiran Feb 01 '15 at 09:20
  • `import Image` won't find `Image`. – Peter Wood Feb 01 '15 at 09:35
  • See [The problem with installing PIL using virtualenv or buildout](http://stackoverflow.com/q/2485295), PIL has had a history of packaging issues. – Martijn Pieters Feb 01 '15 at 09:59
  • However, please keep it to *one question per post*. On Mac, it is *far easier* to install packages for Python that *require the complilation of C code and additional libraries*, if you use Homebrew to manage the additional libraries. You can do without, but why make your life that hard? – Martijn Pieters Feb 01 '15 at 10:00
  • 1
    ues `pillow` instead: https://pypi.python.org/pypi/Pillow – Sazid Feb 01 '15 at 10:05
  • @PeterWood: it would if that is how PIL was installed. And the original project certainly had such problems. Pillow has fixed all that, and even comes with Wheel files for OS X, so all the OP has to do now is install `pip`, then `pip install wheel` and `pip install Pillow`. – Martijn Pieters Feb 01 '15 at 10:12

3 Answers3

6

If you are using PIL, you might be able to use import Image.

If you are using Pillow, you must use from PIL import Image.

This is by design.

Darrick Herwehe
  • 3,553
  • 1
  • 21
  • 30
aclark
  • 4,345
  • 1
  • 19
  • 31
1

1-Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.

2-Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead. so be careful with it

3-Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from PIL.Image import core as _imaging” instead.

Engr Ali
  • 409
  • 1
  • 5
  • 13
0

In python, modules are represented by *.py files. These files can be imported using import module. That statement will first search for a build-in module, if it fails to find one it will search in a given list of directories (PYTHONPATH). When you imported your module, you can then access names (aka functions or classes) via module.name. However, when using from module import myFunc you can reference that function directly without using the modulename. The same goes for from module import *.

Now, to the PIL: Image is a name (here class) in the PIL module. As, import Image searches for modules called Image. It can't find one, because Image is part of the PIL module.

You can also look at the documentation here: Modules in Python

I hope this helped you understanding modules better.

Marco
  • 330
  • 3
  • 12