1

(Please excuse my English)

My server's OS is Ubuntu 20.04. In Ubuntu 20.04, as we know, Python 3.8 is installed by default, and many system applications run on Python 3.8.
I additionally installed Python 3.9 in my Ubuntu server. And my server worked fine for a while.

However, when I upgraded the global modules of Python(3.8 and 3.9 both), the problem occurred. Some system programs, such as Software Updater and Software and Update, are not working. They are giving errors saying that cannot find some Python global modules. I tried to fix the problem by re-installing the python global modules, but could not fix.

I don't need Python 3.9 for the whole server system, only for few non-root user accounts. And the only needed global module are pip and venv. Other modules can be installed on project base.
So, I tried to install Python 3.9 as a non-root user. But some errors occurred, and failed.

How can I safely install Python 3.9(or above) for non-root users?

  • Here, the safe installation means the installation not interfering with the system default Python 3.8.
  • It doesn't matter whether Python 3.9(or above) is installed system-wide or for a specific user.
8
  • @user535733 : It seems that something has been miscommunicated. I edited my post to express my intentions more clearly.
    – pdh0710
    Dec 4 '21 at 19:33
  • One simple way is to use a Python venv. Are you asking how to do that? Or are you asking for more options?
    – user535733
    Dec 4 '21 at 19:53
  • @user535733 : I already wrote in my post that "And the only needed global module are pip and venv", which means I want to use Python 3.9's pip and venv without interfering the system default Python 3.8.
    – pdh0710
    Dec 4 '21 at 21:07
  • In that case, this seems like a duplicate of stackoverflow.com/questions/1534210/…, which includes among its many answers step-by-step instructions and a link to a YouTube tutorial.
    – user535733
    Dec 4 '21 at 21:31
  • @user535733 : I don't know why you are so obsessed with using venv only. I'm already using different Python version with venv. My problem is that one day it interfered with the system Python 3.8. I don't think I'm the only one experiencing this problem. So I posted this question, and want to hear opinions on this problem. Not using venv.
    – pdh0710
    Dec 4 '21 at 22:02
1

You might need to check on which version python3 is mapped.

ls -l /usr/bin/python3

If the symlink is on python3.9, you can try to revert back onto version python3.8 with the following command

cd /usr/bin/
sudo ln -sf python3.8 python3

In fact, it's not a big problem as you can have several system python version. If your user need to use python3.9, just use python3.9 <your script>.py

7
  • Sorry, after reading your question, I just realize I didn't answered to your question. I'm not sure about installing python as non system user, I'm not sure it's feasible.
    – ob2
    Dec 4 '21 at 16:42
  • In my Ubuntu server, /usr/bin/python3 -> python3.8 . I don't why updating global modules makes such a problem.
    – pdh0710
    Dec 4 '21 at 16:43
  • What do you mean by upgrading global modules. You used pip ?
    – ob2
    Dec 4 '21 at 16:45
  • Yes. pip3 install <package_name> --upgrade and pip3.9 install <package_name> --upgrade
    – pdh0710
    Dec 4 '21 at 16:49
  • Consider using virtualenv in that case. Installing packages with pip is generally a bad idea unless you install a server for a specific product.
    – ob2
    Dec 6 '21 at 19:21
1

Ubuntu 20.04 and later has the python3.9 package in its default repositories. It can be installed alongside the default python3.8 package with sudo apt update && sudo apt install python3.9 Installing the python3.9 package from the default Ubuntu repositories simplifies package management.

If you are using Ubuntu 20.04 keep Python 3.8 as the default Python 3.x version and switch to Python 3.9 only when necessary using update-alternatives. After you are done using Python 3.9 you can switch the it back to the default Python 3 version.

  • List installed versions of Python: update-alternatives --list python

  • Switch between Python versions: update-alternatives --config python

    From the terminal command-line Press to keep the current choice[*], or type selection number:

3
  • O.K. I'll try this way. When I installed Python 3.9 version on my server, it was the first time I installed a different version of Python, other than the system default. So there may have been some mistakes I wasn't aware of. I'll re-install Python 3.9 without mistakes as you told.
    – pdh0710
    Dec 5 '21 at 0:41
  • Please uninstall the old version of Python 3.9 before installing the new version of Python 3.9.
    – karel
    Dec 5 '21 at 0:43
  • Of course. I'll re-install the whole Ubuntu server. Fortunately, my Ubuntu server has a simple structure.
    – pdh0710
    Dec 5 '21 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.