Score:1

After installing Python 3.9.6 on Ubuntu 18.04, I could not run sudo apt

cn flag

I didn't know that Python 3.6 had already been installed by some package before I installed Python 3.9.6 onto my system.

I followed the steps found at https://phoenixnap.com/kb/how-to-install-python-3-ubuntu#ftoc-heading-7

  1. sudo apt update
    
  2. sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
    
  3. cd /tmp
    
  4. wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
    
  5. tar -xf Python-3.9.6.tgz
    
  6. cd python-3.9.6
    
  7. ./configure --enable-optimizations
    
  8. (Overwrite Default Python Installation)

    "To install Python 3.9.6 over the top of your existing Python, enter the following":

    sudo make install
    

After these steps, I found out that I have 3 versions of python:

$ python -V
Python 3.6.9
$ python2 -V
Python 2.7.17
$ python3 -V
Python 3.9.6

I then ran:

sudo apt update

The terminal returned:

File "/usr/local/bin/apt", line 6
    print "apt"
              ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("apt")?

I could run other commands like sudo apt-get ... etc.

Could someone please tell me what went wrong?

Edit: Thank you Joshua Johns, steeldriver & vanadium for your help. I did the followings to verify:

$ ls -l /usr/bin/python
/usr/bin/python -> /etc/alternatives/python
$ ls -l /etc/alternatives/python
/etc/alternatives/python -> /usr/bin/python3
$ ls -l /usr/bin/python3
/usr/bin/python3 -> python3.6
$ ls -l /usr/bin/python2
/usr/bin/python2 -> python2.7
$ which python3 /usr/local/bin/python3
$ ls -l /usr/local/bin/python3
/usr/local/bin/python3 -> python3.9
vanadium avatar
cn flag
You cannot change the python version of an Ubuntu system without breaking it. The OS relies on it extensively. You should probably reinstall the default python system to make it work again.
hr flag
It looks like you didn't *really* "install Python 3.9.6 over the top of your existing Python" since the self-built version appears to have gone in `/usr/local` rather than `/usr`. It may be sufficient to delete the symbolic link at `/usr/local/bin/python` for example.
Score:0
il flag

To add on @vanadium whenever you want to install latest python in your machine always check the release date for both python and Ubuntu.its better to upgrade Ubuntu to latest release without breaking everything.for instance python 3.9 was released on October 5th, 2020 while Ubuntu 18.04 was released on July 26, 2018.for now you have to wait for Ubuntu 22.04 which most probably will have python 3.9 by default. Hopefully you get the point now.

Score:0
in flag

I use deadsnakes PPA to safely install the latest python on Ubuntu 18.04 (20.04 installs 3.8 but has 3.9 in its official repository) without overwriting the existing system python. See this gist for details: https://gist.github.com/plembo/6bc141a150cff0369574ce0b0a92f5e7 . Note that my workflow doesn't require the latest python system-wide, so I always add the "--user" flag when installing additional libraries with pip.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.