Python Forum
Upgraded Python: Module no longer found - for Linux
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upgraded Python: Module no longer found - for Linux
#1
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
Reply
#2
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?
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
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
Reply
#4
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
« We can solve any problem by introducing an extra level of indirection »
Reply
#5
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.
Reply
#6
(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...)
« We can solve any problem by introducing an extra level of indirection »
Reply
#7
Thanks Gribouillis, correct on both points.
Reply
#8
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! 😊
Reply
#9
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Upgraded Python: Module no longer found Winfried 1 935 Jan-01-2025, 02:43 PM
Last Post: Larz60+
  Module not found error even though installed NZGeorge 1 4,416 Jul-10-2024, 09:08 AM
Last Post: Larz60+
  Linux, Python, C ++, Brain2 and errors. PiotrBujakowski 0 947 Jun-24-2024, 03:41 PM
Last Post: PiotrBujakowski
  Is possible to run the python command to call python script on linux? cuten222 6 2,277 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  pyside6 module not found ForeverNoob 4 5,573 Aug-18-2023, 04:36 PM
Last Post: snippsat
  I found a problem with Python Lahearle 12 3,299 Jul-20-2023, 10:58 PM
Last Post: Pedroski55
  Beginner: Code not work when longer list raiviscoding 2 1,609 May-19-2023, 11:19 AM
Last Post: deanhystad
  Module Not Found Error bitoded 4 2,538 Jan-01-2023, 09:08 AM
Last Post: bitoded
  pdfminer package: module isn't found Pavel_47 25 16,497 Sep-18-2022, 08:40 PM
Last Post: Larz60+
  Module not found question sighhhh12 0 2,138 Sep-09-2022, 05:43 AM
Last Post: sighhhh12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020