Install & Compatibility
Where this runs
tested against v1.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 0.007s · 65.8MB
glibcpy 3.10–3.940 runs
installs and imports cleanly · install 2.0s · import 0.007s · 20MB
65MB installed
● package 65MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pyqrcode
✓ import pyqrcode
create
✓ from pyqrcode import create
✗ import pyqrcode.create
The `create` function is directly available in the `pyqrcode` module, not as a submodule. Alternatively, call `pyqrcode.create()` after `import pyqrcode`.
This quickstart generates a QR code for a given URL, saves it as an SVG file, and displays it directly in a compatible terminal. For PNG output, ensure 'pypng' is installed.
import pyqrcode
import sys
# Create a QR code for a URL
qr_code_url = pyqrcode.create('https://example.com')
# Save as SVG file
qr_code_url.svg('example-url.svg', scale=8)
print("QR code saved as example-url.svg")
# Print to terminal (requires a compatible terminal)
print("\nQR code in terminal:")
print(qr_code_url.terminal(quiet_zone=1))
pyqrcode --version
Debug
Known issues
gotchaTo generate PNG images, the `pypng` library must be installed separately (`pip install pypng`). Without it, calls to `qr_code.png()` will result in an error.fixInstall `pypng`: `pip install pypng`.
affects: All versions
deprecatedThe library has not seen significant updates since 2018 (version 1.2.1). While functional, it may lack modern features, performance optimizations, or compatibility with very recent Python versions compared to more actively maintained QR code libraries.fixConsider alternatives like `qrcode` for ongoing development or if advanced features and active maintenance are crucial.
affects: 1.2.1 and potentially earlier
gotchaBy default, `pyqrcode.create()` uses the highest error correction level ('H'). While this makes the QR code more robust to damage, it significantly reduces the data capacity. If you need to encode more data, you might need to manually set a lower error correction level (e.g., 'L', 'M', or 'Q') using the `error` parameter.fixSpecify the `error` parameter: `pyqrcode.create('data', error='L')`. affects: All versions
gotchaNaming a Python file or variable `pyqrcode.py` or `pyqrcode` can lead to import conflicts (module shadowing), where Python tries to import your local file/variable instead of the installed `pyqrcode` library.fixAvoid naming your scripts or variables `pyqrcode`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyqrcode'
The pyqrcode library is not installed in the current Python environment.
pyqrcode.errors.PyQRCodereError: PNG output requires PyPNG to be installed.
The optional pypng library, which is necessary for generating PNG images, has not been installed.
AttributeError: module 'pyqrcode' has no attribute 'write_png'
The 'write_png' method (or similar output methods) was incorrectly called directly on the pyqrcode module instead of on an instance of a QRCode object.
fixFirst create a QRCode object, then call 'write_png' on that object. Example: qr = pyqrcode.create('Your data'); qr.write_png('your_code.png') TypeError: QR code data must be bytes or unicode.
The pyqrcode.create() function was passed a non-string/non-bytes object (e.g., an integer or a list) as the data for the QR code.
fixEnsure the data passed to pyqrcode.create() is a string or bytes object. Example: qr = pyqrcode.create('123') Upgrade
Version history
1.2.1latest on PyPI · released Jun 20, 2016
Audit
Dependencies
pypngoptionalRequired for saving QR codes as PNG image files.