ImportError: No Module named 'driver' in pyttsx

Prometheus picture Prometheus · Jan 17, 2017 · Viewed 9.4k times · Source

I am trying to run a voice program in Python 3.5.2 and with pyttsx library. But I've faced up with lots of problems. First one is about engine. When I run the command import pyttsx, compiler gave me the error like below:

ImportError: No module named 'engine'

Then I've found this answer. But it didn't work either. Eventually, I now have another - similar - error like below:

D:\Users\orcuny\Desktop\AVA>python ava.py
Traceback (most recent call last):
File "D:\Users\orcuny\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyttsx\__init__.py", line 37, in init
eng = _activeEngines[driverName]
File "D:\Users\orcuny\AppData\Local\Continuum\Anaconda3\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "ava.py", line 3, in <module>
engine = pyttsx.init()
File "D:\Users\orcuny\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyttsx\__init__.py", line 39, in init
eng = Engine(driverName, debug)
File "D:\Users\orcuny\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyttsx\engine.py", line 45, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "D:\Users\orcuny\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyttsx\driver.py", line 64, in __init__
self._module = __import__(name, globals(), locals(), [driverName])
ImportError: No module named 'drivers'

As far as I can get from the answers all over the SO, I assume that pyttsx library is written in Python 2.X.

My first question is, how can I solve this above problem? The second question is, I couldn't find pyttsx library which is written in Python 3.X. Can anybody enlighten me if there is any pyttsx library that is written in Python 3.X?

Thanks in advance.

EDIT: Adding site-packages to my PATH variables also didn't work.

Answer

fedepad picture fedepad · Jan 21, 2017

Well, the problem seems to be addressed in the following post
import pyttsx works in python 2.7, but not in python3

Can anybody enlighten me if there is any pyttsx library that is written in Python 3.X?

Yes, please use the following version:
https://github.com/jpercent/pyttsx
It is a Python3 port of pyttsx which seems to address the problems you face and targets Python 3.X versions.
For example the error you see (ImportError: No module named 'drivers') is addressed by the following commit
https://github.com/jpercent/pyttsx/commit/f035083338f39f7d93b0c610fbef0bb55fc9fc1c
which was merged in the aforementioned repository.
To install the pyttsx python module, you can

pip install git+git://github.com/jpercent/pyttsx.git

or

pip install git+https://github.com/jpercent/pyttsx.git

or

git clone https://github.com/jpercent/pyttsx.git 
cd pyttsx 
sudo python setup.py install  

or do that inside a virtual environment if you use them. You can avoid using 'sudo' to install, depends on the environment you use and how you organized the packages (locations, etc.).
Of course, use the right python (python3) and pip (pip3) as you have in your environment.
Please remove and clean the previous pyttsx package you had there in the environment.
In addition, you can visit http://pyttsx.readthedocs.io/en/latest/install.html
for more details on that.