I had a program (using module pyttsx3) written in Windows which I used to run on python3.7, and it used to run well.
But,when I try to run it on Ubuntu 20.04, it doesn't run.
I have both python3.8.2 and python3.7.7 installed on my Ubuntu 20.04 PC, running the program with python3.8.2 interpreter gives the following errors:
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
On the other hand, running it with python3.7 interpreter gives the following ModuleNotFoundError:
.
.
.
import pyttsx3
ModuleNotFoundError: No module named 'pyttsx3'
...but, when I check the installed modules using the command pip3 list
, pyttsx3 shows up in the list with version: 2.87
Now, I am clueless!...dunno what to do.
UPDATE-1 (pipenv)
I tried running it with pipenv
using the following commands as suggested in the answer by @ivan-borshchov :
pipenv --three
pipenv install pyttsx3
pipenv run python3 MyPythonFile.py
...but this gives the following errors which are somewhat similar to the errors I get when using python3.8.2 interpreter.
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
UPDATE-2 (pipenv run python3.7 ...)
Okay while fiddling with pipenv
, I found that running python3.7 in pipenv is again giving the ModuleNotFoundError, the same as I get when running my program in python3.7 without pipenv (Even though, I have installed pyttsx3 in pipenv as mentioned in UPDATE-1 section).
So, then I am curious whether it is possible to install pyttsx3 in python3.7 in pipenv(rather than in python3, in pipenv).
Try run your project in
pipenv
:It will give you a clear environment so will allow track issue easier without the influences of another interpreters
First go to the location:
Create a new file
hook-pyttsx3.py
.Inside this file, copy the code below.
Then, in your script, use this:
reference