Python: Create a QR code with pyqrcode

We are using a module that does not come with the Anaconda distribution. To get this code, open up your Anaconda Prompt and type the following code:

> pip install pyqrcode

Next, you will import pyqrcode into python. Also, since the output of this program will be a png picture file, I am running pwd to determine where on my machine the file will be saved.

Next pick a URL you want your QRCode to go to. I chose my website. I assigned my website address to a variable url.

Then, using the pyqrcode module and its method create(), place your variable in the parenthesis ().

Note printing the QR code you created will not display it, but it will give you the basic information on it. To turn it into a QR code, we will need to covert it to a png.

*Note: Some of you may need to download the png module if you get an error. Just go to pip install png and add import png to the top of the script.

Otherwise, just give you file a name, and scale — the larger the scale, the larger your QR code will be.

Finally, go to your directory where the file was saved and open it.

Scanning the QR Code below should take you to my website’s main page.

One thought on “Python: Create a QR code with pyqrcode

  1. Anonymous

    I am getting below error when ran the last piece
    ModuleNotFoundError Traceback (most recent call last)
    Input In [11], in ()
    —-> 1 QRCd.png(‘QRFile.png’, scale=5)

    File ~\Anaconda3\lib\site-packages\pyqrcode\, in QRCode.png(self, file, scale, module_color, background, quiet_zone)
    416 def png(self, file, scale=1, module_color=(0, 0, 0, 255),
    417 background=(255, 255, 255, 255), quiet_zone=4):
    418 “””This method writes the QR code out as an PNG image. The resulting
    419 PNG has a bit depth of 1. The file parameter is used to specify where
    420 to write the image to. It can either be an writable stream or a
    460 background=(0xff, 0xff, 0xff, 0x88)) #50% transparent white
    461 “””
    –> 462 builder._png(self.code, self.version, file, scale,
    463 module_color, background, quiet_zone)

    File ~\Anaconda3\lib\site-packages\pyqrcode\, in _png(code, version, file, scale, module_color, background, quiet_zone, debug)
    1244 def _png(code, version, file, scale=1, module_color=(0, 0, 0, 255),
    1245 background=(255, 255, 255, 255), quiet_zone=4, debug=False):
    1246 “””See: pyqrcode.QRCode.png()
    1248 This function was abstracted away from QRCode to allow for the output of
    1264 modules) to the output (default: “False“).
    1265 “””
    -> 1266 import png
    1268 # Coerce scale parameter into an integer
    1269 try:

    ModuleNotFoundError: No module named ‘png’

Leave a Reply