No module named Image - python

Sorry for my grammar, I don't speak English.
After I set filebrowser, tinymce, and grappelli, I get this error: No module named Image
try:
from PIL import Image
except ImportError:
import Image
I set it to PIL but it didn't solve the problem.
my platform windows
If i want: pip install PIL
`c:\Users\Kim\BitNami DjangoStack projects\homex8>pip install PIL
Downloading/unpacking PIL
Running setup.py egg_info for package PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
building '_imaging' extension
error: Unable to find vcvarsall.bat`
I do not understand what that means
Solved problem.
reinstall PIL with easy_install, and more movements, here are the details.

You are missing PIL (Python Image Library and Imaging package). To install PIL I used
pip install pillow
For my machine running Mac OSX 10.6.8, I downloaded Imaging package and installed it from source.
http://effbot.org/downloads/Imaging-1.1.6.tar.gz and cd into Download directory. Then run these:
$ gunzip Imaging-1.1.6.tar.gz
$ tar xvf Imaging-1.1.6.tar
$ cd Imaging-1.1.6
$ python setup.py install
Or if you have PIP installed in your Mac
pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz
then you can use:
from PIL import Image
in your python code.

Did you setup PIL module? Link
You can try to reinstall it on your computer.

It is changed to : from PIL.Image import core as image
for new versions.

You can this query:
pip install image
I had pillow installed, and still, I got the error that you mentioned. But after I executed the above command, the error vanished. And My program worked perfectly.

Problem:
~$ simple-image-reducer
Traceback (most recent call last):
File "/usr/bin/simple-image-reducer", line 28, in <module>
import Image
**ImportError: No module named Image**
Reason:
Image != image
Solution:
1) make sure it is available
python -m pip install Image
2) where is it available?
sudo find ~ -name image -type d
-->> directory /home/MyHomeDir/.local/lib/python2.7/site-packages/image
->> OK
3) make simple-image-reducer understand via link:
ln -s ~/.local/lib/python2.7/site-packages/image
~/.local/lib/python2.7/site-packages/Image
4)
invoke simple-image-reducer again.
Works:-)

If you are trying to just show the image on your notebook, below simply does the job
from IPython.display import Image
Image(url= "Link to the image ending with file format such as, .jpg or .png")

Related

Unable to import PIL into project

The PIL module should be installed because when I run the pip install pillow I get this message: Requirement already satisfied: pillow in [my installation route]. But, when I try to import this into a file, I get this error:
ModuleNotFoundError: No module named 'Pillow'
What am I doing wrong?
this has worked for me if your using vscode try install by typing py -m pip install pillow
from PIL import ImageTk,Image
Pillow is a fork of PIL, and the import is carried over.
import PIL
Should do the trick. The documentation has additional details:
https://pillow.readthedocs.io/en/stable/installation.html

Heroku PIL ModuleNotFoundError: No module named 'Image'

I am creating a Heroku app in which I am using PIL and from PIL import Image.
When I run heroku local, it returns ModuleNotFoundError: No module named 'Image'. I have tried using Pillow instead of PIL, but it returns the same error. PIL and Pillow are both in my requirements.txt.
A link to my full github repo is: https://github.com/maivey/flower-image-classifier
Please help as I do not understand why it will not recognize PIL or Pillow
Maybe you need to install them.
If you use anaconda: conda install PIL
If you use pip: pip install PIL
Thanks

Importing pytesseract

I have trying to use pytesseract for OCR (extracting text from the image). I have successfully installed pytessearct by using the command -
pip install pytessearct
When I try to install it again, it clearly says -
Requirement already satisfied (use --upgrade to upgrade):
pytesseract in ./site-packages
This means pytessearct is installed successfully. When i try to import this package in my iPython notebook using -
import pytessearct
It throws an error -
ImportError: No module named pytesseract
Why is that happening?
To use Python-tesseract - requires python 2.5+ or python 3.x - first you have to install PIL and pytesseract packages through pip:
pip install Pillow
pip install pytesseract
Then you have to download and install the tesseract OCR:
https://sourceforge.net/projects/tesseract-ocr-alt/?source=typ_redirect
As far as I know it automatically adds it to your PATH variable.
Then use it like this way:
import pytesseract
from PIL import Image
img = Image.open('Capture.PNG')
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe'
print( pytesseract.image_to_string(img) )
I hope it helps :)

Pillow import error from _imaging.so / libjpeg.8.dylib on OSX

I've used Pillow in the past on OSX without problems, however I now get the following error.
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 61, in <module>
from PIL import _imaging as core
ImportError: dlopen(/Library/Python/2.7/site-packages/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /Library/Python/2.7/site-packages/PIL/_imaging.so
Reason: image not found
I've seen this question which appears to be a similar problem but I don't think I installed Pillow with brew.
I've also tried the solution from this question but the command
pip install PIL --allow-external PIL --allow-unverified PIL
dosent seem to work and I get an error (no such option: --allow-unverified)
Lastly, I've tried to recreate the symbolic link to libjpeg.8.dylib but that also did not make any difference.
Would anyone know how to fix this error? Do I need to do something to relink _image.so aswell as libjpeg?
Python PIL was deprecated eons ago and you should not attempt to use it anymore.
What you want is python[23] -m pip install Pillow
PS. Using pip command will be deprecated soon because of confusions regarding python interpreters, instead of calling pip ... everyone should use only python -m pip ... which assures that is calling the right interpreter.

PIL doesn't recognize jpeg library under Mac OS

Scripts like that:
from PIL import Image, ImageOps
img = Image.open('1.JPG')
thumb = ImageOps.fit(img, (200,200) , Image.ANTIALIAS, (0.5, 0.5))
cause this IOError:
Traceback (most recent call last):
(...)
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 385, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
How do I get jpeg support for my PIL? That issue seems to be well known but the existing threads don't solve it for me. I use brew and pip for my python packages and have already tried the following:
brew install jpeg
causes Error: jpeg-8d already installed
brew install libjpeg causes Error: jpeg-8d already installed
sudo pip install Pillow - installation works but does not change anything
How do I get jpeg support for my PIL installation? Any ideas?
I don't understand why, but reinstalling PIL fixed the issue:
sudo pip uninstall pil
sudo pip install pil
I ran into a similar problem on Ubuntu 12.04 64-bit and solved it by symlinking the libraries PIL was looking for into /usr/lib (where it was actually looking for them):
# symlink image libraries so PIL can find them
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib
# etc for any other libraries
For non OSX people landing here, I found linking to the 64 bit libraries on my 64 bit Ubuntu system to fix the compile issue.

Categories

Resources