PyCharm cannot access files in /usr/lib/ and /usr/bin/

Question:

I am using PyCharm 2020.2.3 with Python 3.8.6 under Pop_OS! 20.10 (you can probably do as if I am using Ubuntu 20.10) which is unable to see files into /usr/bin or /usr/lib.

Here is an example if I try to touch the /usr/lib/firefox/firefox binary file.

# main.py
import os
print(os.path.exists('/usr/lib'))
print(os.path.exists('/usr/lib/firefox'))
print(open('/usr/lib/firefox/firefox', 'r'))

From the command line, this works:

>>> python main.py
True
True
<_io.TextIOWrapper name='/usr/lib/firefox/firefox' mode='r' encoding='UTF-8'>

But when I run it in PyCharm, it fails like so:

True         # Can see /usr/lib
False        # Cannot see /usr/lib/firefox
Traceback (most recent call last):
  File ..., line 5, in <module>
    print(open('/usr/lib/firefox/firefox', 'r'))
FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib/firefox/firefox'

Here are the permissions for usr/bin/firefox:

>>> ls -ld firefox
drwxr-xr-x 8 root root 4096 Oct 26 10:22 firefox

There are numerous questions regarding similar issues but most of them end up suggesting a work around related to the specific file required.

There seem to be some kind of permission issue and I want to tackle that without having to rely on a workaround.

Asked By: Olivier Melançon

||

Answers:

After more than one month, I found this thread on intellij-support which explains the issue happens because I installed a PyCharm flatpack.

I eventually figured out my issue was caused by how I installed
pycharm. I had used the app store which installs a flatpack. Due to
how flatpacks work, it installs an isolated environment containing
everything the app needs. With normal apps this could be useful at
the expense of duplicate files using extra disk space, but for
development apps it makes it so you can’t run your code reliably from
inside the flatpack installed app.

— Mvanorder1390 (Created October 30, 2019 13:13)

This was exactly my issue. I reinstalled PyCharm from the official source instead of my app-store which only offered a flatpack version and everything now works like a charm (pun intended)!

Answered By: Olivier Melançon