1. Download the QRCode library first
Use the PIP command:
Pip Install QRCode
The version above python3.x is installed by default, and if there is no information to find the PIP directive, you will need to install PIP first.
2. Then install the PIL Library
The generation of the QR code requires the creation of an image file, and the PIL (Python Image Library) is a third-party library of Python processing images, which is not installed in advance and needs to be installed by the user itself. If the PIL is not installed, it will be reported "Importerror:cannot import Image" error.
We tried to use PIP command pip install PIL could not install, and the PIL Library of the Python official website does not support python3.x version (is not maintained?). -_-)。 See PIL's alternative version of Pillow on the web, using pillow to process images.
Execute command:
Pip Install Pillow
3. Command line to generate two-dimensional code
#coding =utf-8
From PIL import Image
Import QRCode
Q=qrcode.main.qrcode ()
Q.add_data ("http://www.baidu.com")
M=q.make_image ()
M.save ("Hello.png")
Take a closer look at each of these instructions:
(1) Import QRCode: introduction of QRCode Library
(2) from PIL import Image: Introduction of Pillow Library, note the wording OH
(3) Q=qrcode.main.qrcode (): Define Q variable
(4) Q.add_data (""): Set the QR code content, can be text, or it can be a link
(5) M=q.make_image (): Generate two-dimensional code image
(6) M.save ("Hello.png"): Save image as specified name
By default, the image is saved in the D:/python directory, you can go to view, and sweep a try Oh ~
Windows uses python3.4 to generate two-dimensional code