0

I fixed the pyttsx's , engine.py and driver.py file with some help on stackOverflow's solution but the problem still persists ( im trying to run a simple text to speech program )

import pyttsx3 
engine = pyttsx3.init()
engine.say("hello there!")
engine.runAndWait()

the program runs and gives some errors like

Traceback (most recent call last):
File "/home/sawood/Documents/test.py", line 2, in <module>
import pyttsx3
File "/home/sawood/.local/lib/python3.10/site-packages/pyttsx3/__init__.py", line 
1, in <module>
from .engine import Engine
File "/home/sawood/.local/lib/python3.10/site-packages/pyttsx3/engine.py", line 1, 
in <module>
from .driver import driver
ImportError: cannot import name 'driver' from 'pyttsx3.driver' 
(/home/sawood/.local/lib/python3.10/site-packages/pyttsx3/driver.py

any ideas what has happend or what should be done im on a linux (EndeavourOS ~ arch) i have my small project on college to be submitted pls help

1 Answers1

0

I seemed to have found a potential solution! This may or may not work but it looks like your PyInstaller site-package has skipped over some important pyttsx3 stuff. To fix this all you have to do is go to wherever you have Python installed (usually the path looks something like this: "C:\Users[Your User]\AppData\Local\Programs\Python\Python[Your Version]\Lib\site-packages") From there you should be able to locate a package under the folder name 'PyInstaller' (without quotes), then, you can go into the hooks folder, and look for a file called 'hook-pyttsx3.py' (without quotes again). If the file is not present, you will need to create a new python file under that name, and this is what the contents of the file should look like:

#-----------------------------------------------------------------------------
# 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)
#-----------------------------------------------------------------------------





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

If you do have the hook-pyttsx3 file present, make sure the contents match, and if not replace them with this. Hope this helps! p.s. This is one of my first StackOverflow answers I've posted, so if I formatted anything wrong, just let me know! EDIT: At first I didn't see that you were on Linux. This would be the solution (at least I believe it would be) for windows systems, and I do believe it would be something similar for Linux but I can't be entirely sure, sorry for the inconvenience. Hope it works!