I have such code in the beginning of a file:
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
And it throws the error:
python3 main.pyTraceback (most recent call last):
File "main.py", line 1, in <module>
from PIL import Image
ImportError: No module named 'PIL'
According to many ad vices I should just replace import PIL with what I actually have. But is doesn't work as you can see.
It's on Ubuntu 14.04 and Python 3.4.0
According to this you should be able to do import Image instead of import PIL.
Related
Pillow has been added to the project. Here's the code:
from PIL import Image, ImageFilter, ImageDraw, ImageFont
im = Image.open("someImage.jpg")
print(im.width, im.height, im.mode, im.format) # Display
im.show(im)
Pillow is imported and the code runs fine, but PyDev gives the error:
Unresolved import: Image
――――――――――――――――――――
Image Found at: foo
from PIL import Image, ImageFilter, ImageDraw, ImageFont
If I comment out the import statement, I get a different error:
Traceback (most recent call last):
File "C:\ImagePractice\foo.py", line 2, in <module>
im = Image.open("someImage.jpg")
NameError: name 'Image' is not defined
#nicomp if you add PIL to the Forced Builtins in the interpreter you're using, does it work? (see: https://www.pydev.org/manual_101_interpreter.html for more details)
I am trying to import the image module from pillow 5.1.0. Using python 3.6.5.
I typed in the following command
from PIL import image.
Upon doing this I get the following error.
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
from PIL import image
ImportError: cannot import name 'image'
Try from PIL import Image (note the capital 'I' in Image).
I am making a webcam program with tkinter and pillow. I need to use the Image.fromarray() attribute and the ImageTk. But if i install the version of Pillow with Image.fromarray()i can't use ImageTk and vice versa. When i do this i get the error:
Traceback (most recent call last):
File "C:\SignIn\dictionary.py", line 66, in <module>
show_frame()
File "C:\SignIn\dictionary.py", line 51, in show_frame
pil = Image.fromarray(frame)
AttributeError: class Image has no attribute 'fromarray'
I have tried different versions of Pillow but there doesn't seem to be a version that satisfies both. I can't find any one else having this issue online
Modules:
import json
import zbar
import numpy as np
import cv2
import Tkinter as tk
from PIL import Image as y
from PIL import ImageTk
I am new to python and using this tutorial http://code.tutsplus.com/tutorials/how-to-build-a-python-bot-that-can-play-web-games--active-11117 to build a bot which plays games.
I copy-pasted the file and installed the libraries .When i tried running the file in the terminal on my mac i got this error :
Traceback (most recent call last):
File "bot.py", line 2, in <module>
import Image, ImageGrab, ImageOps
File "/Library/Python/2.7/site-packages/PIL/ImageGrab.py", line 34, in <module>
import _grabscreen
ImportError: No module named _grabscreen
Here is the complete code
import os, sys
import Image, ImageGrab, ImageOps
import time, random
from random import randrange
import win32api, win32con
from numpy import *
I think you should pay attention to the these words in the tutorial, 'Some of the code and libraries are Windows-specific. There may be Mac or Linux equivalents, but we won't be covering them in this tutorial.'.
And current version of ImageGrag only works for windows.
I have Pillow and qrcode modules installed in a virtual environment.
From the python shell, I can create a test image programmatically using PIL:
>>> from PIL import Image
>>> img = Image.new('1', (200, 200))
>>> img.save('test-image.jpeg', 'JPEG')
Great, that works just as I would expect it to. However, I'm getting this error when I try to use a module that relies on PIL:
>>> import qrcode
>>> qr_code = qrcode.make("1")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vagrant/.virtualenvs/env1/local/lib/python2.7/site-packages/qrcode/main.py", line 8, in make
return qr.make_image()
File "/home/vagrant/.virtualenvs/env1/local/lib/python2.7/site-packages/qrcode/main.py", line 186, in make_image
from qrcode.image.pil import PilImage
File "/home/vagrant/.virtualenvs/env1/local/lib/python2.7/site-packages/qrcode/image/pil.py", line 5, in <module>
import Image
ImportError: No module named Image
Why can't qrcode import PIL's Image class but it works from the shell?
This is an issue with your installation: Image module have been installed as subpackage of a PIL module, while the library you are using expects Image module to be directly in the python path. Simplest solution is to replace:
import Image
with:
from PIL import Image
in file qrcode/image/pil.py.