本文介绍了import pyttsx 在 python 2.7 中有效,但在 python3 中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:为什么python3在导入pyttsx时找不到引擎模块?

详情:

我正在使用 Raspbian Wheezy 在 raspberry pi 上执行此操作

在python 2.7下,以下工作:

>>>导入pyttsx

在python3下,会发生以下情况:

>>>导入pyttsx追溯(等...)文件<stdin>",第 1 行,位于 <module>文件/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg/pyttsx/__init__.py",第18行,在<module>导入错误:没有名为引擎的模块

我已经安装并使用了 sudo pip install pyttsx

我已经导入了系统

sys.path 包含这个...

>>>打印(系统路径)['','/usr/local/lib/python3.2/dist-packages/setuptools-5.4.1-py3.2.egg','/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg'、'/usr/lib/python3.2'、'usr/lib/python3.2/plat-linux2'、'/usr/lib/python3.2/lib-dynload'、'/usr/local/lib/python3.2/dist-packages','/usr/lib/python3/dist-packages']

ls/usr/local/lib/python3.2/dist-packages 结果...

easy-install.pth pyttsx-1.1-py3.2.egg setuptools-5.4.1-py3.2.egg setuptools.pth

unzip -t/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg 显示....

pyttsx/__init__.py OKpyttsx/voice.py 好的pyttsx/engine.py 好的(等等...)pyttsx-1.1-py3.2.egg 压缩数据中未检测到错误

感谢您的帮助!

解决方案

我相信您正在寻找图书馆:

pyttsx3

这个与 python3 兼容的版本现在打包在 pypi 中,并且对 python2 和 python3 都运行良好,据我测试,它没有给出任何错误.

只需使用:

pip install pyttsx3

用法:

导入pyttsx3引擎 = pyttsx3.init()engine.say("我现在在说");engine.setProperty('rate',100)engine.runAndWait();

Question: why is python3 unable to find the engine module when importing pyttsx?

Details:

I'm doing this on a raspberry pi with Raspbian Wheezy

Under python 2.7, the following works:

>>> import pyttsx

Under python3, the following happens:

>>> import pyttsx
Traceback (etc...)
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg/pyttsx/__init__.py", line 18, in <module>
ImportError: No module named engine

I've installed and used sudo pip install pyttsx

I've imported sys

sys.path contains this...

>>> print (sys.path)
['','/usr/local/lib/python3.2/dist-packages/setuptools-5.4.1-py3.2.egg', '/usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg', '/usr/lib/python3.2','usr/lib/python3.2/plat-linux2', '/usr/lib/python3.2/lib-dynload','/usr/local/lib/python3.2/dist-packages','/usr/lib/python3/dist-packages']

ls /usr/local/lib/python3.2/dist-packages results in...

easy-install.pth pyttsx-1.1-py3.2.egg setuptools-5.4.1-py3.2.egg setuptools.pth

unzip -t /usr/local/lib/python3.2/dist-packages/pyttsx-1.1-py3.2.egg shows....

pyttsx/__init__.py  OK
pyttsx/voice.py   OK
pyttsx/engine.py  OK
(etc...)
No errors detected in compressed data of pyttsx-1.1-py3.2.egg

Thanks for your help!

解决方案

I believe you are looking for the library:

pyttsx3

This python3 compatible version is now packaged in pypi and works pretty well for both python2 and python3 and as far as i have tested , it didn't give any error.

just use :

pip install pyttsx3

Usage :

import pyttsx3
engine = pyttsx3.init()
engine.say("I am talking now ");
engine.setProperty('rate',100)
engine.runAndWait();

这篇关于import pyttsx 在 python 2.7 中有效,但在 python3 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:45