List all python versions

Ubuntu 18 how to install latest python 3.7 and list all python versions

Python is installed by default in Ubuntu and Linux Mint. The version which is installed could be a few versions behind the latest stable release. It is a good idea to list all installed versions on your machine and install the latest ones. The latest versions gives many advantages like:

The following article is tested on Ubuntu 18 and Linux Mint 18. The examples are based on Linux Mint.

List all installed python versions

If you want to see where and what python versions are installed on your machine you can do it by following commands. Check where python is installed:

Then you can list all python installations there by:

the result of this command is:

 0 lrwxrwxrwx 1 root root 9 Nov 24 2017 /usr/bin/python -> python2.7 0 lrwxrwxrwx 1 root root 9 Nov 24 2017 /usr/bin/python2 -> python2.7 3412 -rwxr-xr-x 1 root root 3492656 Dec 4 2017 /usr/bin/python2.7 0 lrwxrwxrwx 1 root root 33 Dec 4 2017 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config 0 lrwxrwxrwx 1 root root 16 Nov 24 2017 /usr/bin/python2-config -> python2.7-config 0 lrwxrwxrwx 1 root root 9 Apr 10 19:43 /usr/bin/python3 -> python3.5 4360 -rwxr-xr-x 2 root root 4464400 Nov 28 2017 /usr/bin/python3.5 0 lrwxrwxrwx 1 root root 33 Nov 28 2017 /usr/bin/python3.5-config -> x86_64-linux-gnu-python3.5-config 4360 -rwxr-xr-x 2 root root 4464400 Nov 28 2017 /usr/bin/python3.5m 0 lrwxrwxrwx 1 root root 34 Nov 28 2017 /usr/bin/python3.5m-config -> x86_64-linux-gnu-python3.5m-config 0 lrwxrwxrwx 1 root root 16 Mar 23 2016 /usr/bin/python3-config -> python3.5-config 0 lrwxrwxrwx 1 root root 10 Apr 10 19:43 /usr/bin/python3m -> python3.5m 0 lrwxrwxrwx 1 root root 17 Mar 23 2016 /usr/bin/python3m-config -> python3.5m-config 0 lrwxrwxrwx 1 root root 16 Nov 24 2017 /usr/bin/python-config -> python2.7-config 

Selection_007

Another way to list python installations is by:

python: /usr/bin/python2.7-config /usr/bin/python3.5 /usr/bin/python3.5m-config /usr/bin/python /usr/bin/python2.7 /usr/bin/python3.5-config /usr/bin/python3.5m /usr/lib/python3.5 /usr/lib/python2.7 /etc/python3.5 /etc/python /etc/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python2.7 /usr/include/python3.5 /usr/include/python2.7 /usr/include/python3.5m /usr/share/python /usr/share/man/man1/python.1.gz 

Alternatively you can see the alternatives with:

update-alternatives --list python 
update-alternatives --list python3 

As you can see from both results we get python 2.7 and 3.5. The latest version of python 3 is 3.7 so if you want to installed it you can check next section. For more information about python 3.7 check here: Python 3.7 new features

Install latest python 3.7 on Ubuntu 18/Linux Mint 18

There are several ways of installing the latest python on Ubuntu:

Install by using PPA repository

There is a PPA which offers many versions of Python:
New Python Versions

Читайте также:  Java метод возвращает интерфейс

This is the description of the repo:

This PPA contains more recent Python versions packaged for Ubuntu. 

Disclaimer: there’s no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

If you want to install 3.7 in this way you can do it by:

sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install python3.7 

After the installation is better to not change the default version for the OS because you can meet many problems and unexpected behavior. Better is to change the version of your IDE or specific programs.

Install by downloading and building from source

First you will need to install some dependencies for the new python version:

sudo apt-get 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 

After that you need to download the version which you want to install. In this case we download Python 3.7 source code from python.org. You can also download the file by visiting the site: python.org donwloads

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz 

Now extract the downloaded package(add sudo if needed).

Now enter the newly extracted source directory, configure the build environment and install.

cd Python-3.7.0 sudo ./configure sudo make altinstall 

Note : If you use make altinstall instead of make install you will keep the default python version (otherwise you can face problems).
Step 4 – Check the Python Version

Check the python version.

Python version can be checked in several ways:

python3 -V python3 --version 

for the newly installed 3.7 you can check it by:

python3.7 -V python3.7 --version 

List all python packages

The new versions of python can be delivered with new packages and versions. So you can check the packages by using these commands:

apt-clone==0.2.1 apt-xapian-index==0.47 apturl==0.5.2 bleach==1.5.0 blinker==1.3 Brlapi==0.6.4 chardet==2.3.0 

If you are using conda or miniconda you can run:

If you want to do the same with python code then you can execute:

By using SoftHints — Python, Linux, Pandas , you agree to our Cookie Policy.

Источник

How to Check all the Python Versions Installed on Linux

How to Check all the Python Versions Installed on Linux 1

In this article, we will see how to check all the python versions installed on a Linux system. Many times you might have noticed that either knowingly or unknowingly you end up installed multiple python versions in your linux system. And some day you only realize this when you started getting certain strange messages on the output pointing different versions of python available in the System. Well, at that point of time you probably would like to know all the python versions installed on your System. While there are many ways to check this but here we will only see four methods that can be used in a linux system to detect all the python versions.

Читайте также:  Python pyqt5 контекстное меню

How to Check all the Python Versions Installed on Linux 2

How to Check all the Python Versions Installed on Linux

Method 1: Using whereis command

The first method you can think of using is through whereis command which is easily available in almost all the linux distributions. So if you are looking for all the versions of python3 then you just need to run whereis python3 command and you will able to see all the python3 versions as shown below. This works great in almost all the linux systems.

cyberithub@ubuntu:~$ whereis python3 python3: /usr/bin/python3 /usr/bin/python3.8 /usr/bin/python3.9 /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3 /etc/python3.8 /etc/python3.9 /usr/local/lib/python3.8 /usr/local/lib/python3.9 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz

Similarly, if you would like to check all the installed versions of python2 then you need to use whereis python2 command as shown below.

cyberithub@ubuntu:~$ whereis python2 python2: /usr/bin/python2.7 /usr/bin/python2 /usr/lib/python2.7 /etc/python2.7 /usr/local/lib/python2.7 /usr/share/man/man1/python2.1.gz

Method 2: Using ls command

The second method that I always love to use is through ls command. This command is also very easily available on almost all the linux distribution. Using this command, you just need to look for all the python binaries available under /usr/bin path to detect all the versions of python currently installed as shown below. You can check more about ls command on 16 Best ls command examples in Linux.

cyberithub@ubuntu:~$ ls -ls /usr/bin/python* 0 lrwxrwxrwx 1 root root 9 Mar 13 2020 /usr/bin/python2 -> python2.7 3580 -rwxr-xr-x 1 root root 3662032 Jul 1 2022 /usr/bin/python2.7 0 lrwxrwxrwx 1 root root 9 Nov 15 20:46 /usr/bin/python3 -> python3.8 5368 -rwxr-xr-x 1 root root 5494584 Nov 14 18:29 /usr/bin/python3.8 5668 -rwxr-xr-x 1 root root 5803968 Nov 23 2021 /usr/bin/python3.9 4 -rwxr-xr-x 1 root root 384 Mar 28 2020 /usr/bin/python3-futurize 4 -rwxr-xr-x 1 root root 388 Mar 28 2020 /usr/bin/python3-pasteurize

Method 3: Using compgen command

Another method that you can think of using is through compgen command. If this utility is available in your system then you need to simply run compgen -c python | grep -P ‘^python\d’ command to list out all the versions of python installed in the system.

cyberithub@ubuntu:~$ compgen -c python | grep -P '^python\d' python3-pasteurize python2.7 python2 python3 python3.8 python3-futurize python3.9 python3-pasteurize python2.7 python2 python3 python3.8 python3-futurize python3.9

Method 4: Using find command

The last method that I would advise to use is through find command. You can search and look for all different python symbolic link under /usr/bin path using find /usr/bin/python* ! -type l command as shown below. You can check more about find command on 40 Best Examples of Find Command in Linux.

cyberithub@ubuntu:~$ find /usr/bin/python* ! -type l /usr/bin/python2.7 /usr/bin/python3.8 /usr/bin/python3.9 /usr/bin/python3-futurize /usr/bin/python3-pasteurize

Источник

How to list all Python versions installed in the system?

Or just keep them in a list, whichever you prefer for this already dirty fix. command to check python version in MacOS check python version ubuntu check all python versions ubuntu how to find python version python version installed in ubuntu Finding interpreters from standard locations would be actually fine.

How to list all Python versions installed in the system?

I need to present the user a list of Python installations to choose from for executing something. I suppose in Windows I could get this information from registry. Don’t know about Linux and Mac.

Читайте также:  Посмотреть версию java windows

Any hints? Or maybe you even know a place where I could find Python code for this?

EDIT: it is not important that I find really all interpreters. Finding interpreters from standard locations would be actually fine. Agreed, it’s not something too difficult, but I was just hoping that maybe someone has code for this lying around or that I’ve overlooked a function for that in stdlib.

I’m writing a Python IDE and I want to let user to choose the interpreter for executing the program.

Just do it like other IDEs then and simply supply a dialog where users can add interpreters they want to be able to run the code with.

Eclipse does this for example for Java Runtimes, and it’s perfectly fine to have it like that. Especially for languages like Python where virtual environments are an important thing which each have their own exectutable.

You certainly can come up with a one- time detection that checks some common locations. For Windows, this would obviously be the registry, as the py.exe launcher requires the interpreters to be registered there—at least the system-wide ones. On Unix machines, you could check the common bin/ folders, most prominently /usr/local/bin/ which is the standard location where Python installs itself. You could also check the PATH for Python executables. But all those things should be considered carefully and only offer an initial setup. There are always edge cases where a user didn’t do the “standard thing” where your detection will fail. For example I don’t have my Python interpreters in my path, and a linux server I access I have installed Python into a non-standard folder in my home directory. And finally, just because it looks like Python doesn’t mean it is Python.

Yes, you can do some guesswork to come up with an initial set of interpreters, but really don’t spend too much time on it. In the end, you won’t be able to detect everything perfectly anyway. And you will miss virtual environments—which might be very crucial to the project the user is working on in your IDE.

So instead of wasting time on bad detection, spend more time on creating a manual dialog to register interpreters. You will need that anyway, and a good interface can make it very easy—even for beginners—to use it.

Not sure this is entirely possible, but here’s a dirty fix:

from subprocess import * from time import sleep for i in range(2, 4): x = Popen('python' + str(i) + ' --version', shell=True, stdout=PIPE, stdin=PIPE, stderr=STDOUT) while x.poll() == None: sleep(0.025) print('Exit code of ' + str(i) + ' is:',x.poll()) x.stdout.close() x.stdin.close() 

The exit code will tell you if Python2 or Python3 is installed. You could add a second iterator for python versions 2.4, 2.4, 3.1, 3.2 etc etc. Or just keep them in a list, whichever you prefer for this already dirty fix.

Источник

Оцените статью