Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'constants' is not defined #377

Open
HopWorks opened this issue Sep 29, 2024 · 0 comments
Open

NameError: name 'constants' is not defined #377

HopWorks opened this issue Sep 29, 2024 · 0 comments

Comments

@HopWorks
Copy link

HopWorks commented Sep 29, 2024

I am guessing this is a python 3.12 issue possibly. This library worked for me before using VSCODE on Windows 11, but it is possible that this was before I removed other versions of Python. It is possible that when it worked, I had python 3.11 targeted as the interpreter.

Is there a fix for 3.12 or do I have to downgrade my Python install?
The error... NameError: name 'constants' is not defined throws when importing qrcode, as in import qrcode.
Error details is below.
Thanks

C:\Users\user>py -0p
 -V:3.12 *        C:\Program Files\Python312\python.exe
 
C:\Users\user>python -m pip list
Package           Version
----------------- ------------
attrs             24.2.0
brother-ql        0.9.4
click             8.1.7
colorama          0.4.6
future            1.0.0
packbits          0.6
pillow            10.4.0
pip               24.2
pypng             0.20220715.0
pyusb             1.2.1
qrcode            7.4.2
typing_extensions 4.12.2

C:\Users\user>py -m pip show qrcode
Name: qrcode
Version: 7.4.2
Summary: QR Code image generator
Home-page: https://github.com/lincolnloop/python-qrcode
Author: Lincoln Loop
Author-email: [email protected]
License: BSD
Location: C:\Program Files\Python312\Lib\site-packages
Requires: colorama, pypng, typing-extensions
Required-by:

C:\Users\user>py
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qrcode
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python312\Lib\site-packages\qrcode\__init__.py", line 1, in <module>
    from qrcode.main import QRCode
  File "C:\Program Files\Python312\Lib\site-packages\qrcode\main.py", line 80, in <module>
    class QRCode(Generic[GenericImage]):
  File "C:\Program Files\Python312\Lib\site-packages\qrcode\main.py", line 87, in QRCode
    error_correction=constants.ERROR_CORRECT_M,
                     ^^^^^^^^^
NameError: name 'constants' is not defined
>>> exit()

From qrcode\main.py (snippet)

 80 class QRCode(Generic[GenericImage]):
 81     modules: ModulesType
 82     _version: Optional[int] = None
 83 
 84     def __init__(
 85         self,
 86         version=None,
 87         error_correction=constants.ERROR_CORRECT_M,
 88         box_size=10,
 89         border=4,
 90         image_factory: Optional[Type[GenericImage]] = None,
 91         mask_pattern=None,
 92     ):

To reproduce, open a windows command line terminal, enter a python REPL environment by typing python and pressing enter, then try import qrcode and press enter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant