Reputation: 107
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?
Upvotes: 5
Views: 5072
Reputation: 359
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.
Upvotes: 1
Reputation: 4345
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
.
Upvotes: 6
Reputation: 330
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.
Upvotes: 0