Thidal
Thidal

Reputation: 109

Python - QRCode error "No module named 'image'"

I am trying to create an QRCode by using the 'qrcode' library. However, when I try to make an image, I get the following error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\qrcode\image\pil.py", line 6, in <module>
    from PIL import Image, ImageDraw
ImportError: No module named 'PIL'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/Floris/Documents/GitHub/MiniProject-GroepV1L/TEST_QR.py", line 4, in <module>
    img = qrcode.make(string)
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\qrcode\main.py", line 11, in make
    return qr.make_image()
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\qrcode\main.py", line 256, in make_image
    from qrcode.image.pil import PilImage
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\qrcode\image\pil.py", line 8, in <module>
    import Image
ImportError: No module named 'Image'

The code I have right now is:

import qrcode

string = "This is a test string for StackOverflow"
img = qrcode.make(string)

Upvotes: 6

Views: 15573

Answers (3)

Jon
Jon

Reputation: 374

For a standard install (which will include pillow for generating images), run:

pip install qrcode[pil]

(docs)

Upvotes: 2

Hvitis
Hvitis

Reputation: 555

Apparently after downloading the package with the pil command from readme:

pip3 install[pil]

I had to apply the quotations for the bash purposes in order to download it with PIL:

pip3 install"[pil]"

and because I was doing it after some time, I run upgrade just in case:

pip3 install"[pil]" -U

The StyledPilImage is neither in qrcode package neither in PIL package (I searched both of them). I don't see how creating those qr codes with nice, rounded dots would be possible now with just installing this with pip.

Solution

In order to have those beautiful, rounded-corner qr codes with nice colours:

Twitter

You just need to have the code that you are looking form properly imported. Where from?

The official repo of course. Download it with e.g. git (or just copy the functions you need)

git clone https://github.com/lincolnloop/python-qrcode.git

and copy the qrcode folder from the downloaded repo to your pip packages folder.

I copied them to my site-packages folder which has the qrcode package:

lib/python3.7/site-packages/qrcode

to see where you have it run:

pip list -v

and it works like a charm.

The thing is that the README was changed for the repo but the last verified tag on it was 6.1 which did not have styles. It needs to be updated cause current version that I am running (and works) is 7.1

@EDIT

It is updated now. Just run:

pip install PACKAGE_NAME -U 

Upvotes: 1

Lucas Infante
Lucas Infante

Reputation: 798

You have to install Pillow:

pip install pillow

And probably some other dependencies.

You should have installed the qrcode package using pip so that the dependencies would have been installed.

Upvotes: 7

Related Questions