ImportError:pyttsx中没有名为“driver”的模块

2024-06-01 01:46:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图在Python 3.5.2中使用pyttsx库运行一个语音程序。但我已经面对了很多问题。第一个是关于引擎。当我运行命令import pyttsx时,编译器给出如下错误:

ImportError: No module named 'engine'

然后我找到了this answer。但也没用。最后,我又出现了一个类似的错误,如下所示:

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'

从所有的答案中我可以得到,我假设pyttsx库是用Python 2.X编写的。

我的第一个问题是,如何解决上述问题? 第二个问题是,我找不到用Python 3.X编写的pyttsx库。如果有用Python 3.X编写的pyttsx库,有人能告诉我吗?

提前谢谢。

编辑: 将网站包添加到我的路径变量也不起作用。


Tags: inpyinitliblocallinesiteusers
3条回答

嗯,这个问题似乎在下面的帖子中得到了解决
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?

是的,请使用以下版本:
https://github.com/jpercent/pyttsx
它是一个Python3端口pyttsx,似乎可以解决您面临的问题,并针对Python3.X版本 例如,您看到的错误(ImportError: No module named 'drivers')通过以下提交来解决 https://github.com/jpercent/pyttsx/commit/f035083338f39f7d93b0c610fbef0bb55fc9fc1c
合并到上述存储库中。
要安装pyttsxpython模块,可以

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

或者

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

或者

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

或者在虚拟环境中使用它们。您可以避免使用“sudo”进行安装,这取决于您使用的环境以及如何组织软件包(位置等)。
当然,在您的环境中使用正确的python(python3)和pip(pip3)。
请移除并清理环境中以前的pyttsx包。
此外,您还可以访问http://pyttsx.readthedocs.io/en/latest/install.html
更多细节。

网站包中没有包含您的PY_HOME或PATH。请打开环境变量并将其添加到系统变量中。

添加如下内容,您还会在文件夹下看到所需的包。

C:\where_your_python_installation\Lib\site-packages

希望有帮助

你可以安装

pyttsx3型

它与python3和python2都兼容,并且在我测试的范围内是无错误的。

安装:

pip install pyttsx3

相关问题 更多 >