I have a problem with library "pyttsx3". I think the main problem is with PyCharm, because espeak work fine from terminal and same code, that not work in PyCharm, work in Jupter Notebook. I don't have an idea, what can I do more.
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
Code above work normal in Jupyter, but PyCharm throw me an error: OSError: libespeak.so.1: cannot open shared object file: No such file or directory
That library is installed here: /usr/lib/x86_64-linux-gnu/libespeak.so.1
This not work: Run -> Edit Configurations -> Environment -> LD_LIBRARY_PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/libespeak.so.1
PyCharm 2022.2.1 Community Edition, Ubuntu 22.04. I have installed every required dependencies like espeak and so on. Code only not work in PyCharm.
First edit:
Ok, so I'm not sure, what does it mean "when ldd is run from inside pycharm.". You mean the same command, but inside pycharm using for example os packages? If yes, then check below.
ldd from terminal
linux-vdso.so.1 (0x00007ffce3b70000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9c9f421000)
libpcaudio.so.0 => /lib/x86_64-linux-gnu/libpcaudio.so.0 (0x00007f9c9f41a000)
libsonic.so.0 => /lib/x86_64-linux-gnu/libsonic.so.0 (0x00007f9c9f414000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c9f000000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9c9f5be000)
libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2 (0x00007f9c9f30e000)
libpulse-simple.so.0 => /lib/x86_64-linux-gnu/libpulse-simple.so.0 (0x00007f9c9f305000)
libpulse.so.0 => /lib/x86_64-linux-gnu/libpulse.so.0 (0x00007f9c9f2b0000)
libpulsecommon-15.99.so => /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.99.so (0x00007f9c9f22b000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f9c9efb2000)
libsndfile.so.1 => /lib/x86_64-linux-gnu/libsndfile.so.1 (0x00007f9c9ef33000)
libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f9c9ef2e000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f9c9edee000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f9c9edc4000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f9c9ecfd000)
libasyncns.so.0 => /lib/x86_64-linux-gnu/libasyncns.so.0 (0x00007f9c9ecf5000)
libapparmor.so.1 => /lib/x86_64-linux-gnu/libapparmor.so.1 (0x00007f9c9ece0000)
libFLAC.so.8 => /lib/x86_64-linux-gnu/libFLAC.so.8 (0x00007f9c9eca4000)
libvorbis.so.0 => /lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f9c9ec75000)
libvorbisenc.so.2 => /lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f9c9ebca000)
libopus.so.0 => /lib/x86_64-linux-gnu/libopus.so.0 (0x00007f9c9eb6c000)
libogg.so.0 => /lib/x86_64-linux-gnu/libogg.so.0 (0x00007f9c9eb61000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f9c9eb5b000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f9c9eb53000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f9c9eb26000)
libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f9c9ea57000)
liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f9c9ea37000)
libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007f9c9ea2c000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f9c9e8ee000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f9c9e8d4000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f9c9e8ae000)
libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007f9c9e8a1000)
inside PyCharm: ldd: /usr/lib/x86_64-linux-gnu/libespeak.so.1: No such file or directory
I installed PyCharm as flatpak, I created new project, and I imported pyttsx3 inside PyCharm. I clicked on the name, and it was imported to my project. I imported it manually too (Python Interpreter -> + -> package name), but nothing change. Pyttsx3 is also installed globally using PIP (probably that code work on Jupyter). Typing in terminal pip install pyttsx3
tells me:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pyttsx3 in ./.local/lib/python3.10/site-packages (2.90)
About ctypes:
Traceback (most recent call last):
File "/home/rob/Documents/test/main.py", line 22, in <module>
ctypes.cdll.LoadLibrary('/usr/lib/x86_64-linux-gnu/libespeak.so.1')
File "/usr/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.9/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/lib/x86_64-linux-gnu/libespeak.so.1: cannot open shared object file: No such file or directory
About LD_LIBRARY_PATH
- I change to LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/
and now error is: OSError: libespeak.so.1: cannot open shared object file: No such file or directory
About espeak: espeak: /usr/bin/espeak /usr/share/man/man1/espeak.1.gz