danielhrisca / asammdf

Fast Python reader and editor for ASAM MDF / MF4 (Measurement Data Format) files
GNU Lesser General Public License v3.0
655 stars 226 forks source link

Setting QT_API to pyside6 breaks PyQt Application #1064

Closed mw25 closed 2 months ago

mw25 commented 3 months ago

Python version

('python=3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)]') 'os=Windows-10-10.0.19045-SP0' 'numpy=1.26.4' 'asammdf=7.4.5'

Code

Code snippet

Console:

pip install asammdf, PyQt5, qasync

Python:

import os

print(os.getenv("QT_API"))
from asammdf import MDF
print(os.getenv("QT_API"))

# import qasync
# from PyQt5.QtWidgets import QApplication, QWidget
# 
# app = QApplication([])
# widget = QWidget()
# 
# widget.show()
# app.exec()

Traceback

None
ldf is not supported
xls is not supported
xlsx is not supported
yaml is not supported
pyside6

When I activate the commented lines:

None
ldf is not supported
xls is not supported
xlsx is not supported
yaml is not supported
pyside6
Traceback (most recent call last):
  File "D:\dev\mdftest\test.py", line 7, in <module>
    import qasync
  File "D:\dev\mdftest\Lib\site-packages\qasync\__init__.py", line 58, in <module>
    QtModule = importlib.import_module(QtModuleName)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'PySide6'

Description

I have an application with PyQt5 in which I use asammdf as a library for reading files (I have not installed the asammdf GUI). However, when asammdf is imported, the QT_API environment variable is set to pyside6. In my case (the commented out code is a minimal example of my application), the application crashes when I import qasync. This is because this library queries the environment variable with the wrong value.

danielhrisca commented 3 months ago

@mw25 please try the development branch code

mw25 commented 3 months ago

Unfortunately, it doesn't work yet. I think because of another os.environ["QT_API"] = "pyside6": https://github.com/danielhrisca/asammdf/blob/development/src/asammdf/gui/__init__.py#L3