0

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

JohnLocke
  • 29
  • 4
  • 1
    [Edit] the output of `ldd /usr/lib/x86_64-linux-gnu/libespeak.so.1` into your question -- first from a terminal where espeak works, and a second time _when `ldd` is run from inside pycharm_. – Charles Duffy Sep 15 '22 at 23:46
  • 1
    Also, make sure you're including any relevant details -- if you have pycharm running code inside a container, that's _extremely_ relevant. – Charles Duffy Sep 15 '22 at 23:48
  • 1
    Consider also testing with ctypes: try running `import ctypes; ctypes.cdll.LoadLibrary('/usr/lib/x86_64-linux-gnu/libespeak.so.1')`, and tell us what exception it throws. – Charles Duffy Sep 15 '22 at 23:50
  • 1
    ...often, this kind of problem means pycharm is forcing load of a library that espeak is incompatible with (conflicting versions or such), but there's really not enough information to run it down in this question as currently written. – Charles Duffy Sep 15 '22 at 23:51
  • 1
    Also, `LD_LIBRARY_PATH` should include names of _directories_, not names of individual libraries. It's `LD_PRELOAD` used to force specific libraries to be loaded whether or not the application at hand needs or wants them. (On which point -- if pycharm is using a LD_PRELOAD hook for something, that's an easy way to get compatibility issues). – Charles Duffy Sep 15 '22 at 23:53
  • 1
    How did you install pycharm? This sounds like you used something like flatpak or another packaging system that runs it in a sandbox instead of giving it full access to your system. – Charles Duffy Sep 16 '22 at 00:46
  • 1
    ...oh, yeah, you say that right in the question. Don't use flatpak for tools that can't be sandboxed. – Charles Duffy Sep 16 '22 at 00:46
  • Ok, so should I try to install in without flatpak, and then check, is something change? – JohnLocke Sep 16 '22 at 00:47
  • 1
    Right. Don't use flatpak -- install it properly with a native OS vendor package. – Charles Duffy Sep 16 '22 at 00:47
  • 1
    See https://docs.flatpak.org/en/latest/sandbox-permissions.html describing the constraints you're under. *No access to any host files except the runtime, the app, ~/.var/app/$FLATPAK_ID, and $XDG_RUNTIME_DIR/app/$FLATPAK_ID. Only the latter two being writable.* -- obvs., `/usr/lib/x86_64-linux-gnu` isn't in that list of permitted exceptions. – Charles Duffy Sep 16 '22 at 00:49

0 Answers0