我有一个用pyttsx3编写的程序(使用模块),我以前在python3.7上运行,它过去运行得很好。
但是,当我尝试在Ubuntu20.04上运行它时,它不会运行。
我在我的Ubuntu20.04 PC上安装了python3.8.2和python3.7.7,使用python3.8.2解释器运行程序会产生以下错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.8/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 "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 19, in <module>
core("I am ready", "a", "b")
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 17, in core
voice.core(x, id)
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/voice.py", line 15, in core
engine = pyttsx3.init()
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/drivers/_espeak.py", line 18, in <module>
dll = cdll.LoadLibrary('libespeak.so.1')
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory另一方面,使用python3.7解释器运行它可以获得以下ModuleNotFoundError:
.
.
.
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'...but,当我使用命令pip3 list检查已安装的模块时,pyttsx3显示在版本为2.87的列表中
现在,我是无所适从的!...dunno该怎么办。
更新-1 (pipenv)
我尝试使用@ivan的答复中建议的以下命令使用pipenv运行它:
pipenv --three
pipenv install pyttsx3
pipenv run python3 MyPythonFile.py...but提供了以下错误,这些错误与我在使用python3.8.2解释器时得到的错误有些相似。
Traceback (most recent call last):
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.8/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 "axon.py", line 6, in <module>
import proice
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 19, in <module>
core("I am ready", "a", "b")
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/proice.py", line 17, in core
voice.core(x, id)
File "/home/aakash/ax-net/home/a/ax-thrusters/axon/voice.py", line 15, in core
engine = pyttsx3.init()
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File "/home/aakash/.local/share/virtualenvs/axon-aTooHeXl/lib/python3.8/site-packages/pyttsx3/drivers/_espeak.py", line 18, in <module>
dll = cdll.LoadLibrary('libespeak.so.1')
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory更新-2 (pipenv run python3.7 3.7.)
在摆弄pipenv时,我发现在pipenv中运行python3.7再次给出了ModuleNotFoundError,就像在python3.7中运行没有pipenv的程序一样(尽管,我已经在pipenv中安装了pyttsx3,如更新-1部分中提到的那样)。
因此,我想知道是否有可能在pipenv的python3.7中安装pyttsx3 (而不是python3中的pipenv)。
发布于 2020-05-12 19:10:07
尝试在pipenv中运行您的项目:
pipenv --three
pipenv install pyttsx3
pipenv run python3 yourfile.py它将给你一个清晰的环境,这样就可以在不受其他口译员影响的情况下更容易地解决轨道问题。
发布于 2020-09-30 18:36:53
先到地点:
C:\Users\username\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\PyInstaller\hooks 创建一个新文件hook-pyttsx3.py。
在此文件中,复制下面的代码。
#-----------------------------------------------------------------------------
# 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)
#-----------------------------------------------------------------------------
""" pyttsx3 imports drivers module based on specific platform. Fount at https://github.com/nateshmbhat/pyttsx3/issues/6 """
hiddenimports = [
'pyttsx3.drivers',
'pyttsx3.drivers.dummy',
'pyttsx3.drivers.espeak',
'pyttsx3.drivers.nsss',
'pyttsx3.drivers.sapi5', ]然后,在您的脚本中,使用以下内容:
import pyttsx3
from pyttsx3.drivers import sapi5https://askubuntu.com/questions/1238666
复制相似问题