lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.41k stars 676 forks source link

AttributeError: <class 'segno.QRCode'> object has no attribute to_artistic #378

Open jpavonmCBRE opened 2 weeks ago

jpavonmCBRE commented 2 weeks ago

I'm having an error when executing a python code with qrcode and qrcode-artistic when compiled with pyinstaller. In my case, the code works when executing the python code as it is (as code by using 'python mycode.py'), BUT it does not work if I compile the code using pyinstaller. (pyinstaller does not return any error)

This is the error that I got when running the exe file:

  File "ORIGINAL_code.py", line 349, in <module>
  File "ORIGINAL_code.py", line 323, in main
  File "segno\__init__.py", line 970, in __getattr__
AttributeError: <class 'segno.QRCode'> object has no attribute to_artistic
[7552] Failed to execute script 'ORIGINAL_code' due to unhandled exception!

Line 349 calls the main() block. Lines 322 and 323 have this code:

qr = helpers.make_wifi(ssid, guestPsk, security)
qr.to_artistic(background='green.png', target='QR-CODE.png', dark='#012A2D', data_dark='#003F2D', data_light='white', scale=8)
heuer commented 2 weeks ago

Segno is a different project and not related or compatible to this project.

The "to_artistic" method is added to a QRCode object iff qrcode-artistic is installed, see https://segno.readthedocs.io/en/latest/artistic-qrcodes.html for details.

Since Segno should not have any dependencies and can natively create PNG without Pillow, a few functions that require Pillow have been outsourced to the qrcode-artistic project.

I have no experience with PyInstaller, but I suspect that the qrcode-artistic package is missing.

jpavonmCBRE commented 2 weeks ago

No, the qrcode-artistic module is there, as I mentioned above, the code runs without any error or problem when executed as Python code file (code.py) but it does not run when compiled as .EXE file.

heuer commented 2 weeks ago

As said, I have no experience with PyInstaller, but I suspect that PyInstaller does not recognize qrcode-artistic as a dependency because it is never explicitly imported and the method is added dynamically, at runtime, to the QRCode object. Maybe this helps: https://pyinstaller.org/en/stable/operating-mode.html#analysis-finding-the-files-your-program-needs

jpavonmCBRE commented 2 weeks ago

But I finally found that removing the "DARK=" and "DATA_DARK=" attributes from "qr.to_artistic" it works.

heuer commented 2 weeks ago

to_artistic supports data_dark etc.:

>>> qr.to_artistic(background='background.jpg', target='result.png', data_dark='green', data_light='yellow', dark='blue')

Please open an issue in Segno's repository if you encounter problems: https://github.com/heuer/segno