there seems to be an incompatibility between PySide6 and pyttsx3
-
Hello. below is simple code for regenerating error :
import sys import pyttsx3 from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton class MainWindow(QMainWindow): def __init__(self): super().__init__() self.button = QPushButton("Play") self.button.clicked.connect(self.play_sound) self.setCentralWidget(self.button) self.engine = pyttsx3.init() def play_sound(self): self.engine.say("hello") self.engine.runAndWait() if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
OS : Windowss 11 laptop
IDE : Pycharm(Anaconda), virtual env
Python Ver : 3.9.16I suspect there is a collision between ShibokenSupport in Qt & pyttsx3, as shown by this error message :
C:\Users\hlfan.conda\envs\UAV_GCS\python.exe C:/Users/hlfan/PycharmProjects/speak_practice/main.py
Traceback (most recent call last):
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3_init_.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\weakref.py", line 137, in getitem
o = self.datakey
KeyError: NoneDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 330, in find_cookie
line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byteDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hlfan\PycharmProjects\speak_practice\main.py", line 21, in <module>
window = MainWindow()
File "C:\Users\hlfan\PycharmProjects\speak_practice\main.py", line 13, in init
self.engine = pyttsx3.init()
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3_init_.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3\engine.py", line 30, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3\driver.py", line 50, in init
self.module = importlib.import_module(name)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module>
import pythoncom
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "shibokensupport/signature/loader.py", line 61, in feature_imported
File "shibokensupport/feature.py", line 137, in feature_imported
File "shibokensupport/feature.py", line 148, in _mod_uses_pyside
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\inspect.py", line 1024, in getsource
lines, lnum = getsourcelines(object)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\inspect.py", line 1006, in getsourcelines
lines, lnum = findsource(object)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\inspect.py", line 831, in findsource
lines = linecache.getlines(file, module.dict)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\linecache.py", line 46, in getlines
return updatecache(filename, module_globals)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\linecache.py", line 136, in updatecache
with tokenize.open(fullname) as fp:
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 394, in open
encoding, lines = detect_encoding(buffer.readline)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 371, in detect_encoding
encoding = find_cookie(first)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 335, in find_cookie
raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for 'C:\Users\hlfan\.conda\envs\UAV_GCS\lib\site-packages\pywin32_system32\pywintypes39.dll'Process finished with exit code 1
What I tried :
I tried reinstalling packages with different versions, but it didn't work. Using only PySide6 or only pyttsx3 works great, but if I combine them, I get an error. It seems that there is an incompatibility between these two libraries. -
Hello. below is simple code for regenerating error :
import sys import pyttsx3 from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton class MainWindow(QMainWindow): def __init__(self): super().__init__() self.button = QPushButton("Play") self.button.clicked.connect(self.play_sound) self.setCentralWidget(self.button) self.engine = pyttsx3.init() def play_sound(self): self.engine.say("hello") self.engine.runAndWait() if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
OS : Windowss 11 laptop
IDE : Pycharm(Anaconda), virtual env
Python Ver : 3.9.16I suspect there is a collision between ShibokenSupport in Qt & pyttsx3, as shown by this error message :
C:\Users\hlfan.conda\envs\UAV_GCS\python.exe C:/Users/hlfan/PycharmProjects/speak_practice/main.py
Traceback (most recent call last):
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3_init_.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\weakref.py", line 137, in getitem
o = self.datakey
KeyError: NoneDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 330, in find_cookie
line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byteDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\hlfan\PycharmProjects\speak_practice\main.py", line 21, in <module>
window = MainWindow()
File "C:\Users\hlfan\PycharmProjects\speak_practice\main.py", line 13, in init
self.engine = pyttsx3.init()
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3_init_.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3\engine.py", line 30, in init
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3\driver.py", line 50, in init
self.module = importlib.import_module(name)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module>
import pythoncom
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "shibokensupport/signature/loader.py", line 61, in feature_imported
File "shibokensupport/feature.py", line 137, in feature_imported
File "shibokensupport/feature.py", line 148, in _mod_uses_pyside
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\inspect.py", line 1024, in getsource
lines, lnum = getsourcelines(object)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\inspect.py", line 1006, in getsourcelines
lines, lnum = findsource(object)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\inspect.py", line 831, in findsource
lines = linecache.getlines(file, module.dict)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\linecache.py", line 46, in getlines
return updatecache(filename, module_globals)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\linecache.py", line 136, in updatecache
with tokenize.open(fullname) as fp:
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 394, in open
encoding, lines = detect_encoding(buffer.readline)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 371, in detect_encoding
encoding = find_cookie(first)
File "C:\Users\hlfan.conda\envs\UAV_GCS\lib\tokenize.py", line 335, in find_cookie
raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for 'C:\Users\hlfan\.conda\envs\UAV_GCS\lib\site-packages\pywin32_system32\pywintypes39.dll'Process finished with exit code 1
What I tried :
I tried reinstalling packages with different versions, but it didn't work. Using only PySide6 or only pyttsx3 works great, but if I combine them, I get an error. It seems that there is an incompatibility between these two libraries.@atmega328 Problem solved.
-
A atmega328 has marked this topic as solved on
-
@atmega328 Problem solved.
@atmega328 Hi,
What was the issue ?
How did you fix it ?
It might help other people. -
@atmega328 Problem solved.
@atmega328 Would you please share your solution? I faced the same problem using Pyside6 with dronecan!