Search code examples
pythonpycharmpython-venv

Weirdest behaviour (pycharm, python, virtual environment, loading error)


Long story short: python "sees" some files but not others. the console inside pycharm

the files are there

And this is what I'm trying to do:

I want to use "enchant" spellchecking lib in python. I've written some code that works perfectly in external terminal (= linux terminal = system shell), but fails when I run under pycharm. The error message is "ImportError: The 'enchant' C library was not found and maybe needs to be installed." These are other infos somehow related to the problem:

  • I'm on Linux Pop OS
  • the project has a virtual environment set up (python 3.11, and system is 3.10.12)
  • the installed pyenchant in the venv is 3.2.2, I've also forced to 3.0.0 as seen somewhere, nothing improves
  • I've tried "sudo systemctl stop apparmor" but it doesn't change anything. When apparmor is active it doesn't show any new entry when the code fails
  • The code was giving that error on the system terminal, then I installed "python3-enchant" from deb package manager and it started working, but only in the terminal, not in pycharm
  • pycharm is installed via flatpak
  • I've overwritten the files in the venv pip package (pyenchant) with the contents from the deb package, with no luck. then I've restored the original ones
  • I've tried adding global variables to pycharm runtime configuration. If I run the script without global variables I get the "ImportError", but if I add "PYENCHANT_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/libenchant-2.so.2" to runtime configuration, I get "OSError: cannot open shared object file: No such file or directory", that means, thinks the file doesn't exist, as shown in the screenshots.

In short, I don't think it's a problem specific from the pyenchant library. I just find VERY weird that the simplest os.path.exists fails to detect the presence of some files, but detects others. They all are in the same folder and have similar attributes (readable permissions). I can't understand what is happening.


Solution

  • Thanks to @metatoaster for suggesting the right answer!! Apparently the issue is related to flatpak.

    I solved the issue by uninstalling Pycharm from flatpak, then downloading the .tar.gz from Jetbrains website and "installing" that one (actually just unpacking).