I compiled my program using pyinstaller, python file working fine when not compiled, but throwing the error when i compiled & tested it.
This is the full error, I think this might be because of pyinstaller
Traceback (most recent call last):
File "site-packages\pyttsx3\__init__.py", line 20, in init
File "c:\python37\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "song_dl.py", line 25, in <module>
engine = pyttsx3.init('sapi5')
File "site-packages\pyttsx3\__init__.py", line 22, in init
File "site-packages\pyttsx3\engine.py", line 30, in __init__
File "site-packages\pyttsx3\driver.py", line 50, in __init__
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers'
[1072] Failed to execute script song_dl
Take a look at When things went wrong section of the docs And in particular, the Listing hidden imports
It looks like pyinstaller is not able to "know" it need to add this particular module, so you need to specify it explicitly
probably something like
$ pyinstaller --hidden-import=pyttsx3.drivers song_dl.py