Windows uses python3.4 to generate two-dimensional code

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.