avatarYanick Andrade

Summary

The author shares a cautionary tale of attempting to install Python 3.12 on Linux, encountering numerous issues, and ultimately returning to Ubuntu with Python 3.10 due to system stability and compatibility requirements.

Abstract

The article recounts the author's troublesome experience with installing Python 3.12 on their Linux system. Initially excited about the new features of Python 3.12, the author's attempt to set it as the default version led to a series of problems, including a broken Ubuntu installation and issues with Fedora 39. The author's efforts to resolve these issues, such as changing symbolic links and removing previous Python versions, resulted in further complications, necessitating a complete reinstallation of the operating system. Eventually, the author learned from these mistakes and provided a detailed guide on how to install Python 3.12 without breaking the system, emphasizing the importance of maintaining the default Python version that comes with the Linux distribution for system stability.

Opinions

  • The author regrets their decision to install Python 3.12 and the subsequent attempt to set it as the default version due to the ensuing complications.
  • Fedora 39, despite coming with Python 3.12, was not a viable option for the author due to issues with Google Chrome and Cloudflare connectivity.
  • The author expresses dissatisfaction with the hidden Grub menu in Fedora 39, which hindered access to the Windows partition.
  • The author considers their experience a learning opportunity, leading to a more stable system upon reinstallation of Ubuntu.
  • The author suggests that Linux users should be cautious when upgrading Python versions and consider the potential impact on core system dependencies, such as apt_pkg.

Read This Before You Install Python3.12 On Linux

Don’t repeat the same mistakes as I

I was sweating while fixing my computer — AI-Generated Image by the Author

This might sound like a horror movie to some people (for me it was).

What a week, indeed.

After publishing my previous article about the 3 cool Python 3.12 things you should know, I tried to install and set it as my default Python version.

Little did I know that I was in for a treat.

I broke my Ubuntu.

I installed Fedora 39, which, by the way, comes with Python 3.12.

Initially, Fedora 39 seemed promising with its user-friendly interface and sleek design. But I realized that Google Chrome was having a hard time working and I’m not into Firefox anymore.

Also, I was not able to connect to Cloudflare, which is something I need to be able to access my company’s GitLab and work.

So, I decided to try Windows (sad face).

But guess what? By default, Fedora hides the Grub menu, so I was not able to boot into my Windows in case I needed to do the work there.

After spending hours and hours trying to solve the grub menu issue and barely doing anything productive for 2 days trying to get everything working fine, I decided to give up on Fedora.

I reinstalled my Ubuntu, managed to connect to Cloudflare, and finished the things I had pending. Guess what? I’m still using Python 3.10 because it is the version that comes by default in Ubuntu.

If you use Linux, I will give you a tip that I did not find in any of the guides to install Python3.12. So sticky to the end

But how did all this happen? What did I do wrong?

Let’s follow up on the part where I installed Python 3.12 and tried to set it as default.

Installing Python 3.12 is easy and it can be done in two different ways:

a) You can do it by installing from the Personal Package Archive (PPA)

b) Or, you can do it by compiling and installing from source code.

Both will do the same job. In my case, I did with the option a). I got the Python 3.12 working just fine on my computer.

The thing is, when you install a new version of Python, it’s not set as the default version on your computer. You need to set it manually if you want to make things easier for you.

python3 --version # the default Python on Ubuntu. It can be 3.10, 3.11 (depends)

When you install Python 3.12, this is how you execute its commands:

python3.12 --version

To make sure that your default Python is the new one installed, you need to change the symbolic link (symlink) to point to the right version, which is the new one installed.

So far, everything seems easy. The problem came when I set Python3.12 as default, my Ubuntu complained that the package apt_pkg was not installed.

When you change the symlink, you’re no longer related to Python3.10 or the previous version on your computer. And the apt_pkg I had installed was for Python3.10.

After doing some research, I found a solution that says to run the following command:

sudo apt install python3-apt # install apt_pkg

But this was installed only for Python3.12. I started to think that maybe a) there’s no apt_pkg for Python3.12 and b) because I still have Python3.10 on my computer, this is messing with the installation.

Because I’m a genius (so I thought), I decided to run the following command:

sudo apt remove python3.10

What a horrible mistake.

I hit enter and started removing Python3.10. All of a sudden, my computer closed and all I could see was a black screen with a terminal-alike thing open asking for my username and password.

That’s when I knew I messed up — AI-Generated Image by the Author

Removing Python3.10 from my Ubuntu broke everything because of the core dependencies that my computer had on it.

And the rest you already know, I had to reinstall everything from zero.

Not everything was bad news.

After installing Ubuntu for the last time and accidentally removing Windows from my computer, I decided to install Python3.12 using the option b).

This is how you can do it without breaking your computer

— First, make sure you download the tarball

From the official Python website, you can download the zipped tarball file and extract it:

tar -xf Python-3.12.0.tar.xz && cd Python-3.12.0 # extract everything from file

— Second, build and install Python3.12 from source

This command extracts everything and enters the extracted folder. From the extracted folder run the following command:

./configure --enable-optimizations && sudo make -j4 && sudo make altinstall

This command will configure and install Python3.12 on your computer.

— Last but not least, set Python3.12 as the default

python3.12 --version # prints the version of your Python

As you can see, this is still annoying. You shouldn’t have to type the version every time you need to use it.

The solution is to make it as default. First, find where the Python3.12 installation is located:

whereis python3.12 # prints /usr/local/bin/python3.12 in my case

Create a symlink that will work as an alternative for Python3.10:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1

In my case, only creating the symlink was enough to set it as default, but you might need to choose the version you want to set as default:

sudo update-alternatives --config python3

This will list all Python versions installed and you can choose the version you want to set as default.

Happy end — AI-Generated image by the Author

Very Important tip for Linux users!

If you are a Linux user, you might experience this error after installing and setting Python3.12 as default:

ModuleNotFoundError: No module named 'apt_pkg' in Ubuntu

This error happens because, in my case, Ubuntu comes with Python3.10 by default, unlike Fedora 39, which comes with Python3.12.

And since you set Python3.12 as default, Linux(Ubuntu) will not recognize the apt_pkg installed, which is for Python3.10:

ls apt_pkg.cpython-*
# apt_pkg.cpython-310-x86_64-linux-gnu.so

And because your apt is broken, you can guess that you will not be able to install or update anything.

This is a core dependency on Python from Linux that broke my computer when I removed Python3.10

— Solution for apt_pkg

Remove the current apt_pkg installed:

sudo apt remove python3-apt && sudo apt autoremove

Install it again and it will be linked to your new Python3.12 and everything will work fine:

sudo apt clean && sudo apt install python3-apt

Now you are good to go with Python3.12 and the apt working properly as expected.

python3 --version # Python 3.12.0
sudo apt update # apt working fine as well

Final thoughts

As you can see, I broke my Ubuntu and still went back to it again. I guess I love the suffering.

This experience was good and helpful. This new installation is working much better than the previous one. The previous one gave me some hard times with apps crashing and I couldn’t edit videos using DaVinci Resolve.

In this new one, I’m able to use DaVinci Resolve and edit videos without problems, and apps are no longer crashing and forcing me to reboot the computer every time.

Python
Python Programming
Programming
Data Science
Python3
Recommended from ReadMedium