Although this is a reasonably well documented problem, I can't find a solution.
I cannot import PIL and ImageTK.
Minimal example:
import Tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
image = Image.open('live.ppm')
photo = ImageTk.PhotoImage(image)
This produces the error:
File "C:\Anaconda\lib\site-packages\PIL\ImageTk.py", line 181, in paste
import _imagingtk
ImportError: No module named _imagingtk
I have tried:
conda install pillow
conda remove PIL
But no luck.
After uninstalling pillow and PIL:
pip install image
Fixed this issue.
Thanks for bringing this up. The ImageTk module is an extra extension that is not part of the default installation of Pillow.
This issue is long-standing: https://github.com/ContinuumIO/anaconda-issues/issues/150
We (Continuum) will investigate adding this module to our build process.
Try to verify the extension of the image, i got the same problem, and when i modified the extension the script worked
Related
I am on Windows 10 and my python 3 code is as follows:
from tkinter import *
from PIL import ImageTk, Image
root = Tk()
root.title("Images")
root.iconbitmap("C:/Users/[name]/mu_code/GUI Practice/icon.ico")
# my_img = ImageTk.PhotoImage(Image.open("threat.jpg")
button_quit = Button(root, text="Exit Program", command=root.destroy)
button_quit.pack()
root.mainloop()
When I try to run this it gives the following error:
Traceback (most recent call last):
File "c:\users[name]\mu_code\gui practice\images.py", line 2, in
from PIL import ImageTk, Image
ModuleNotFoundError: No module named 'PIL'
I have used pip install to download Pillow and attempted to download it to different locations to fix the problem but could not as the command prompt stated that the module was already downloaded. How can I fix this issue?
Edit:
import Image
or
import ImageTk
doesn't work either.
I have already run pip install Pillow and have one interpreter, being 'Mu'
What you see here as PIL is actually pillow library
from PIL import ImageTk, Image
Run the command:
pip install Pillow
Check out for PIL
Try to use Import Image, and PIL starts working ( it works in my case):
import Image
instead of
from PIL import Image
What I did is:
Open CMD typed "pip install pillow" if you have not yet install pillow
Copied "PIL" folder from
[C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python39\Lib\site-packages]
Then paste it to
[C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python39\Lib]
I am writing a plugin for Ultimaker Cura which uses the Python Imaging Library.
Cura has it's own python environment and uses Python 3.5.7.
I want my plugin to be usable for any Cura user, so I have to include PIL in my plugin inside a subdirectory, and because it's _imaging module is written in C, I have to include precompiled versions of PIL for Python 3.5 which i got from here: https://pypi.org/project/Pillow/#files
I included the cp35 win_amd64 version for windows under "lib_win" and the cp35 manylinux1_x86_64 version for linux under "lib_linux". Here is my code:
if sys.platform == 'win32':
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib_win"))
from PIL import Image
from PIL import ImageFilter
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageChops
if sys.platform == 'linux':
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib_linux"))
from PIL import Image
from PIL import ImageFilter
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageChops
This works without any issues for windows. Under linux, i get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dipl/.local/share/cura/4.6/plugins/SVGReader/lib_linux/PIL/Image.py", line 93, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging'
I have "_imaging.cpython-35m-i386-linux-gnu.so" inside the lib_linux/PIL directory, but it does not recognize this.
I have checked other posts with the same error, but they either have older versions of PIL installed, or use the wrong precompiled version, or are missing a DLL. None of this is the case here.
I also have a working version of PIL on my linux system, and the include code and the PIL code look exactly the same, only the python version number is different.
In case you need it, here is the full sys.path for the Cura python environment (my plugin is SVGReader): https://i.stack.imgur.com/Mixzi.png
(Had to use my own console because Cura doesn't come with one)
So, why does it not recognize _imaging? Any ideas?
in case anybody has the same issue, it's really just as simple as changing the filename of the _imaging library. Name it _imaging.so, or create a symlink to it called _imaging.so. No idea why it works on other platforms without doing that. Might need to rename some other stuff in the same manner, too.
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.
I cannot seem to figure out how to fix a problem with my code regarding import ImageTK from PIL. I have searched and downloaded Pillow different ways and the error of the code is still the same.
Traceback (most recent call last):
File "8_Age_Calculator_App.py", line 3, in <module>
from PIL import Image, ImageTK
ImportError: cannot import name 'ImageTK'
These are the import codes of the file
import PIL
from PIL import Image, ImageTK
import tkinter as tk
import datetime
and this is the code that is trying to import the image
main_image = Image.open('/Users/Brenden/Documents/Python_OOP/old-people-
running-illo_h.jpg')
main_image.thumbnail((100,100), Image.ANTIALIAS)
main_photo = ImageTK.Photoimage(main_image)
main_label_image = tk.Label(image=main_photo)
main_label.grid(column=1, row=0)
How may I fix this problem?
Use this command for Python 3
sudo apt-get install python3-pil.imagetk
You have a typo in the module you want to import. The k in ImageTk should be lower case:
from PIL import Image, ImageTk
this should solve your problem
and in your script you have another case typo, PhotoImage is CamelCase:
main_photo = ImageTk.PhotoImage(main_image)
Install it using this command.
sudo apt-get install python-imaging-tk
ImageTK is k(small letter) not K (capital letter)
from PIL import Image, ImageTk
To install for python2 type in terminal:
sudo apt-get install python-pil.imagetk
For python3 type:
sudo apt-get install python3-pil.imagetk
To import Image and ImageTk:
from PIL import Image, ImageTk
There's a typo in your script, it will be PhotoImage:
main_photo = ImageTk.PhotoImage(main_image)
Try to write this command in the terminal:
pip install pillow
It will install PIL packages
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