3

When I try to install Python 3.8 terminal says it is done, but when I run python --version it says Python 3.7.

(base) user@admin:~$ sudo apt-get install python3.8
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3.8 is already the newest version (3.8.2-1ubuntu1.2).
The following packages were automatically installed and are no longer required:
  libllvm9 libllvm9:i386
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 38 not upgraded.
(base) user@admin:~$ python --version
Python 3.7.6
Zanna
  • 70,465
  • 1
    The python 3.8 is most likely installed. You can verify it by running which python3.8 which will print /usr/bin/python3.8. The python command You are running is just a symlink inside the /usr/bin/ folder pointing to python 3.7.6 – Michal Przybylowicz Jul 24 '20 at 19:57
  • Oh! I see thanks! But so how can I connect Py3.8 to VScode. Because my vscode Python is on version 3.8 but I can't import any modules because of version different my terminal? Have any solutions for that ? – Burak Çolak Jul 24 '20 at 20:03
  • @BurakÇolak Please update Your question with what exactly are You trying to achieve. – Michal Przybylowicz Jul 24 '20 at 20:35
  • what does (base) in front of your prompt status mean? are you installing it in a conda/python environment? – abu_bua Jul 24 '20 at 20:39

2 Answers2

10

As per the instructions on How to Install Python 3.8 on Ubuntu, Debian and LinuxMint – TecAdmin, try the following:

Prerequisites:

Install [and or update] the following packages; build-essential, checkinstall, libreadline-gplv2-dev, libncursesw5-dev, libssl-dev, libsqlite3-dev, tk-dev, libgdbm-dev, libc6-dev, libbz2-dev, libffi-dev, zlib1g-dev.

sudo apt install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

Thereafter, change directory (cd) to your opt folder [or any convenient folder] and download the python source code from python's server:

First change directory (cd) to the 'opt' folder:

cd /opt/

Download the source code

sudo wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz

Extract the [downloaded] source code files

sudo tar xzf Python-3.8.3.tgz

Change directory (cd) the Python Folder [created after the extraction]

cd Python-3.8.3

Compile the source code

sudo ./configure --enable-optimizations

then

sudo make altinstall

Once the compilation is completed, you can confirm that Python 3.8 has been installed successfully with:

python3.8 -V

You should see the response Python-3.8.3.

However, to precisely answer your question, python 3.8 isn't available via ubuntu official repos. You would have to add a PPA to get python 3.8 using sudo apt install [python3.x.x].

The process is described on How to Install Python 3.8 on Ubuntu 18.04 | Linuxize

Hope this helps and I hope I answered your question adequately.

Kulfy
  • 17,696
  • 1
    python 3.8 isn't available via ubuntu official repos: As per Ubuntu package search, Python 3.8 is available for all versions starting from 18.04. Also, I use 20.04 as my primary installation and Python 3.8 is the default Python 3 in that. See release notes of Focal Fossa. – Kulfy Jul 25 '20 at 15:19
  • libreadline-gplv2-dev seems obsoleted. libreadline-dev is installed though. – harryghgim May 17 '23 at 03:30
  • @harryghgim hi, Just a brief couple of questions: Did you get a chance to try to continue with the compilation and installation? If so, how did it go [was it successful]? – Alvindera97 Sep 30 '23 at 00:46
  • 1
    @Alvindera97 It was a while ago, so I might remember incorrectly. I did compile it after installing packages. During compilation readline related tasks was unsuccessful, so I googled and installed other readline package. It worked after that. – harryghgim Oct 02 '23 at 08:17
  • @harryghgim alright, thanks ✌ – Alvindera97 Oct 06 '23 at 17:53
0

It looks like Python 3.8 is already installed but not set as default. Python 3.7.6 is set as default.

Update default Python3 version by below command.

sudo update-alternatives --config python3

Choose Python 3.8 option and check Python version again.

KK Patel
  • 19,083
  • I assume OP is using 20.04 (since 3.8.2-1ubuntu1.2 is available in Focal as per Ubuntu package search). Python 3.8 is already set to be the default python3. Changing it would have made many applications to behave abnormally. As per the question, it seems they made python a symlink/alias to 3.7. So, they need to update alternatives for python. Moreover, AFAIK, alternatives for Python and Python 3 aren't "installed" to be configured by default. You might need to -install them first. – Kulfy Jul 25 '20 at 15:12