Python - QRCode 错误“没有名为‘图像’的模块”

Thi*_*dal 3 python qr-code

我正在尝试使用“qrcode”库创建一个 QRCode。但是,当我尝试制作图像时,出现以下错误:

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'
Run Code Online (Sandbox Code Playgroud)

我现在拥有的代码是:

import qrcode

string = "This is a test string for StackOverflow"
img = qrcode.make(string)
Run Code Online (Sandbox Code Playgroud)

Luc*_*nte 6

你必须安装枕头:

pip install pillow
Run Code Online (Sandbox Code Playgroud)

可能还有其他一些依赖项。

您应该已经使用 pip安装了qrcode包,以便安装依赖项。

  • 我通过 Pip 安装 - 不包括枕头。 (4认同)