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.
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'm trying to create a function which reads pptx files. The only module I found is python-pptx. But unfortunately, it raises errors.
There were some problems with installing Pillow when I did: pip install python-pptx so I installed it easy_install Pillow which seems to be working. Then I installed python-pptx. The problem is that when I execute the function it still raises error:
Traceback (most recent call last):
File "C:/Users/Milano/Desktop/Projekty/FS Dropbox/Dropbox/word_counter.py", line 38, in <module>
print get_pptx_word_count('pptx.pptx')
File "C:/Users/Milano/Desktop/Projekty/FS Dropbox/Dropbox/word_counter.py", line 15, in get_pptx_word_count
from pptx import Presentation
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\__init__.py", line 15, in <module>
from pptx.api import Presentation # noqa
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\api.py", line 17, in <module>
from .package import Package
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\package.py", line 16, in <module>
from .parts.image import Image, ImagePart
File "C:\Users\Milano\Desktop\Projekty\venvs\sfl_venv\lib\site-packages\pptx\parts\image.py", line 13, in <module>
import Image as PIL_Image
ImportError: No module named Image
What should I do? I'm on virtualenv. Tried to uninstall Pillow and install PIL but it didn't find anything.
pillow moves all the PIL modules to the PIL package. You will need to modify the import to PIL.Image.
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.