Python Forum

Full Version: Upgraded Python: Module no longer found - for Linux
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Don’t know if this is the correct place for this question, if not just help out on where I should go?

A thread here titled “[SOLVED] Upgraded Python: Module no longer found” (https://python-forum.io/thread-43804.html?
highlight=No+module+named+%27tkinter%27) gives this fix:

For others' benefit, here's the fix:
    1 pip3 freeze --path c:\Users\joe\AppData\Local\Programs\Python\Python312\Lib\site-packages\ > python_requirements.txt
    2 pip3 install -r python_requirements.txt
This seems like a fix for pycharm on windows, this looks like the same problem I’m having, is there a fix for Linux mint?

curbie
Please include details about your own problem, not details of someone else's (bad) fix to another problem
  • How did you upgrade your Python in Linux Mint?
  • Which module is no longer found?
  • Are you having this problem in an IDE or also on the command line?
  • Add exception traceback perhaps?
Mint Xfce was loaded from scratch to a clean SSD, all upgrades came from the “Software Manager” using the deb option if available, I don’t think I had to load any from flatpacks yet. I did a search of the home directory for tkinter.py, but only found tkinter.pyi. I loaded Mint, then Python, then Pycharm.

The code that failed in this example was a working tutorial from w3school.

curbie

Mint Xfce 22

PyCharm 2024.3.1.1 (Community Edition)
Build #PC-243.22562.220, built on December 18, 2024
Runtime version: 21.0.5+8-b631.28 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.X11.XToolkit
Linux 6.8.0-51-generic
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4002M
Cores: 12# 36 widgets *** Ttk Widgets ***
import tkinter as tk # import tk interface module
from tkinter import ttk # get Tk themed routines
#
Registry:
ide.experimental.ui=true
i18n.locale=Mint Xfce was loaded from scratch to a clean SSD, all upgrades came from the “Software Manager” using the deb option if available, I don’t think I had to load any from flatpacks yet. I did a search of the home directory for tkinter.py, but only found tkinter.pyi.

The code that failed in this example was a working tutorial from w3school.

System:
Mint Xfce 22

IDE:
PyCharm 2024.3.1.1 (Community Edition)
Build #PC-243.22562.220, built on December 18, 2024
Runtime version: 21.0.5+8-b631.28 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.X11.XToolkit
Linux 6.8.0-51-generic
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4002M
Cores: 12# 36 widgets *** Ttk Widgets ***
import tkinter as tk # import tk interface module
from tkinter import ttk # get Tk themed routines
#
Registry:
ide.experimental.ui=true
i18n.locale=
llm.show.ai.promotion.window.on.start=false
Current Desktop: XFCEtkinter

Version:
Python 3.12.3

First 4 lines of Code:
# 36 widgets *** Ttk Widgets ***
  import tkinter as tk                    # import tk interface module
  from tkinter import ttk                 # get Tk themed routines
#
Traceback:
Error:
/home/curbie/.cache/JetBrains/PyCharmCE2024.3/demo/PyCharmLearningProject/.venv/bin/python /home/curbie/PycharmProjects/alpha/amimagev2/36 gui-widget.py Traceback (most recent call last): File "/home/curbie/PycharmProjects/alpha/amimagev2/36 gui-widget.py", line 2, in <module> import tkinter as tk # import tk interface module ^^^^^^^^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'tkinter' Process finished with exit code 1
I don't know pycharm, but try to open a terminal in pycharm and type
Output:
python -m pip install tkinter
You can also try to install the system's "python3-tk" package, probably
Output:
apt-get install python3-tk # or sudo apt-get install python3-tk
For Python 3.12.3, I tried: ":~$ python3 -m pip install tkinter" and it replied:
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
(Jan-29-2025, 09:35 AM)Curbie Wrote: [ -> ]For Python 3.12.3, I tried: ":~$ python3 -m pip install tkinter" and it replied:
error: externally-managed-environment
That's a problem with modern ubuntu (or mint) systems: the default Python is meant for the system, not for ordinary users.

Anyway, I dont think you can install tkinter with pip.

Have you tried the command apt install python3-tk ? (or apt-get or sudo apt...)
Thanks Gribouillis, correct on both points.
You're in the right place! I can definitely help with this.

If you upgraded Python on **Linux Mint** and are now getting a **ModuleNotFoundError**, it likely means your new Python installation doesn’t have the necessary packages installed.

### **Steps to Fix It on Linux Mint:**

#### **1. Check Your Installed Python Versions**
Run:
`bash
python3 --version
python3 -m pip --version
`
Make sure Python and pip are properly installed.

#### **2. Locate Your Site-Packages Directory**
If your modules were installed under the old Python version, they won’t be available in the new one. You can list installed packages with:
`bash
pip3 freeze > python_requirements.txt
`
This saves all currently installed packages to a file.

#### **3. Reinstall Packages for the New Python Version**
Run:
`bash
pip3 install --user -r python_requirements.txt
`
This will reinstall everything for your current Python version.

#### **4. For Missing tkinter (or other built-in modules)**
If you specifically need tkinter, install it with:
`bash
sudo apt install python3-tk
`

#### **5. If You’re Using PyCharm**
If this issue is happening in **PyCharm**, check your **Python Interpreter settings** and make sure it’s pointing to the correct Python version.

---

### **Extra Tip: Use a Virtual Environment**
To avoid issues when upgrading Python in the future, consider using a virtual environment:
`bash
python3 -m venv myenv
source myenv/bin/activate
pip install -r python_requirements.txt
`
This keeps dependencies isolated.

Let me know if you need more details! 😊
Sece1967,

Thanks for the reply, after a few weeks of testing i'm pretty sure I'm now properly setup, at least I can't find any problems.

curbie