ImportError: No Module named 'driver' in pyttsx
Asked Answered
C

4

12

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.

Clove answered 17/1, 2017 at 10:48 Comment(1)
This seems to be already answered: #24964138Cubical
I
10

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.

Ivan answered 21/1, 2017 at 21:23 Comment(0)
D
2

site-packages hasn't included your PY_HOME or PATH. Please open Enviroment Variables and add it to the System Variable.

Add something like below, also you will see required packages under the folder.

C:\where_your_python_installation\Lib\site-packages

Hope it helps

Duncandunce answered 17/1, 2017 at 10:53 Comment(1)
Unfortunately, now I am seeing ImportError: No module named 'drivers' error. @DuncandunceClove
P
1

You can install

pyttsx3

which is compatible with both python3 and python2 and is error free as far as i have tested.

Install:

pip install pyttsx3

Pricking answered 26/6, 2017 at 4:17 Comment(0)
L
0

In CMD run this command it will remove all the issue , I just tried it. pip install -Iv pyttsx3==2.6 -U

Lancelancelet answered 19/4, 2020 at 8:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.