Import Image on windows - python

I have problem with import Image library in Python 2.7 on Windows. When I write:
import Image
I have error:
No module named Image
Library is added in project settings so I tried
from PIL import Image
Unfortunately now I have next error
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
I have no idea what to do.

For windows:
python -m pip install Pillow
then in your python code:
from PIL import Image

Related

"Unused import: Image" error when trying to import a function

I downloaded Pillow using pip and am trying to import its Image package to use the rotate function that is in the Image package, but when I use
from PIL import Image
I get an
Unused import: Image
error along with a
found at PIL.Image 1
message. Does anybody know what this means or what I'm doing wrong?

Pillow can't import

I have a Problem with the Pillow module.
So basically i tried the methods on this website installing it per pip install Pillow and also importing it per from PIL import Image and import PIL none of them worked
I would really appreciate it if someone helped
and thanks for reading. This is my code:
import pyautogui
import pyscreeze
from PIL import Image
lkchat = pyautogui.locateCenterOnScreen("python.png")
print ("lkchat")
I'm getting the following error message:
from PIL import Image
ImportError: No module named PIL
Kitty Star i would like to suggest you that replace PIL with pillow and then install pillow if your code does not run let me know the next error.

How to import pyHook on Spyder (Python 3.7)

I'm trying to use pyHook to get my image to change when I click on it with the mouse. But when I run my code, I get an error.
My Code:
from __future__ import print_function
from PIL import Image
import pyHook
import pythoncom
im = Image.open("H:/---------/Images/nature.jpg")
print(im.format, im.size, im.mode)
im.show()
def OnMouseEvent(event):
im1 = Image.open("H:/----------/Images/nature.jpg").convert("L")
im1.show()
hm = pyHook.HookManager()
hm.MouseLeft = OnMouseEvent
hm.HookMouse()
pythoncom.PumpMessages()
This is the error:
ModuleNotFoundError: No module named 'pyHook'
Screenshot:
Open up your terminal and type:
pip3 install pyHook
It is case-sensitive. So type it properly.
After that, your python environment will have pyHook installed as a module and you will be able to successfully import in your code
EDIT:
Try the following steps since you find the above did not work.
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook
Check your computer system and download the correct .whl file.
Open up your computer's terminal and navigate to your .whl file location. Example: cd C:\Users\ycx\Desktop
Type in: pip3 install pyHook‑1.5.1‑cp37‑cp37m‑win_amd64.whl This part should be your exact filename which you downloaded off the website.

Wand + ImageMagick + Anaconda: "'wand' has no attribute 'image'"

I'm having issues using these three together. I believe wand is not recognizing the ImageMagick libraries but I'm not sure.
Environment:
Python 3.5.1 :: Anaconda 4.0.0 (64-bit)
Windows 7
Set up instructions I took:
Installed ImageMagick-6.9.4-Q8 (x64) with the "C/C++ development
headers options checked. (Installed to C:\Program
Files\ImageMagick-6.9.4-Q8)
Set MAGICK_HOME envar C:\Program Files\ImageMagick-6.9.4-Q8
Installed wand from pip
My code:
import wand
...
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
...
Traceback:
Traceback (most recent call last):
File ".\pdf_convert.py", line 31, in <module>
ret = pdf2jpg(f, target_file, 2480)
File ".\pdf_convert.py", line 10, in pdf2jpg
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
AttributeError: module 'wand' has no attribute 'image'
From everything I've seen I've followed the right setup instructions. I am using the 64 bit version of ImageMagick with the 64 bit version of Anaconda. This was working with me before until I started using Anaconda (before I was using regular 32 bit Python and 32 bit ImageMagick.)
Is there something I'm missing? Why is wand not working correctly?
Try this
from wand.image import Image
with Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
pass
Is there something I'm missing? Why is wand not working correctly?
I believe it is working as expected, and the original architect did not intend to allow top-package-level shortcuts (i.e. import wand). This kinda makes sense as wand integrates to IM with ctypes, and does not attempt to resolve libraries during setup.py.
You can modify the package to include the module shortcuts your expecting by adding the following.
# wand/__init__.py
import api
import color
import compat
import display
import drawing
import exceptions
import font
import image
import resource
import sequence
import version
But I wouldn't recommend this. The from package.module import Class is a lot more cleaner.
If you are using PIL.Image as well then use:
from wand.image import Image as wand_image_Image
import PIL

Import pillow without installing

I am working on a Python project that requires PIL to show images. However, the computers that I am working on often do not allow me to install things, and have a very bare bones python setup. For this reason, most of the modules that I need I simply place in the same directory as my python files.
I tried doing the same with PIL. I downloaded the pillow source, and copied the PIL folder into my project. I was then able to run "import PIL" with no problems. However, when I then tried to run "from PIL import Image" I get the error: "The _Imaging C module is not installed". From other searches I think that installing Pillow properly would fix this problem, however I would like PIL to be more portable, and not require an instillation.
Any ideas would be great. Thanks in advance.
One solution is bundle PIL in with the script in .egg form. Then, you can import PIL directly from the .egg instead of having to install it:
How to create Python egg file
The basic process is as follows:
How to create egg:
Edit PIL's setup.py to include from setuptools import setup instead of normal setup import
Run python setup.py bdist_egg
Egg will be inside of dist/
How to import egg:
Copy .egg file to script's directory and import desired modules:
import os
import sys
DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(DIR, "./path/to/PIL.egg"))
#You can now import from PIL normally:
from PIL import Image

Categories

Resources