Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'pyttsx3.drivers' (File Compiled with pyinstaller), but working fine as uncompiled

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
like image 371
Pushpender Singh Avatar asked Dec 31 '22 15:12

Pushpender Singh


1 Answers

First, go to the folder where your python.exe file is installed, then go to this directory:

\Lib\site-packages\PyInstaller\hooks

You have to install pyinstaller first before going into the directory. Then look in the hooks folder and see if there is a file named:

hook-pyttsx3.py

There is a strong possibility that the file might not be present. So, you have to create hook-pyttsx3.py in the hooks folder and in the file you have to write:

#-----------------------------------------------------------------------------
# Copyright (c) 2013-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------


""" pyttsx3 imports drivers module based on specific platform. Fount at https://github.com/nateshmbhat/pyttsx3/issues/6 """


hiddenimports = [
    'pyttsx3.drivers',
    'pyttsx3.drivers.dummy',
    'pyttsx3.drivers.espeak',
    'pyttsx3.drivers.nsss',
    'pyttsx3.drivers.sapi5', ]

Save the file. Then run your code. The problem will be solved (at least it worked for me.) This problem came because pyinstaller is not updated officially to use python 3.8 fully, so hooks of some modules are missing

like image 88
Lakshya Saxena Avatar answered Feb 17 '23 18:02

Lakshya Saxena