The Linux Mint Software Manager includes the popular Python IDE PyCharm Community, but it’s a Flathub Flatpak and cannot access Python modules installed by Software Manager as System Packages.
For example, after using Software Manager to install Python3 and Python3-tk (System Packages) and PyCharm Community (Flathub Flatpak), try running a simple “Hello, world!” script in PyCharm that opens a Tkinter window:
import tkinter as tk
root = tk.Tk()
w = tk.Label(root, text="Hello, world!")
Instead of a Tkinter window appearing, PyCharm shows the error:
ModuleNotFoundError: No module named 'tkinter'
The error is because the execution environment of the PyCharm Flatpak is separate from the main system, where the tkinter module has been installed.
I’m sure there are other solutions and workarounds, but the simplest solution for me was switching to the official tarball release from JetBrains. PyCharm from the JetBrains release will execute in the main system and have access to all the modules installed there.
Download the release .tar.gz archive for Linux from JetBrains (https://www.jetbrains.com/pycharm/download/?section=linux). After it has downloaded, navigate to your ~/Downloads directory using the GUI file manager (Nemo) and double-click the archive to open it in Archive Manager. Drag the “pycharm-community-yyyy-x.y” folder from Archive Manager to a convenient location where PyCharm will be executed from (I put the folder in my home directory, aka ~ aka /home/username/).
As described in the Install-Linux-tar.txt file in the archive, PyCharm is executed using the bin/pycharm.sh shell script. The first time PyCharm is executed it will create configuration files stored in ~/.config/JetBrains/… (the Install-Linux-tar.txt file has more details).
For convenience, I added the path to pycharm.sh to my bash shell path so I can execute PyCharm from a terminal session without having to remember the full path. To do this, I added the following line to the end of ~/.bashrc:
I also added a menu entry for PyCharm to the Programming folder in the Linux Mint menu for convenient desktop access.
To do this, right-click on the Linux Mint menu button and select Configure, then Menu, Open the menu editor, Programming folder and finally New Item. Click the Browse button and browse to pycharm.sh to create the command line, enter a Name (and if you wish a comment), click the icon box and search for a PyCharm logo, leave the “Launch in terminal” box unchecked, and finally click OK to close the menu editor. For more detailed instructions, search the web for adding a launcher to the Linux Mint menu.
Now PyCharm has no trouble opening a Tkinter window.