This article covers how to install python2 and python3 on CentOS 8. By default, python2 and python3 are not installed on CentOS 8. To install both, you need to install all python packages separately according to python versions. Also, you can run python2 and python3 environments on your system.
The 'alternatives --auto python' command is used to set any python version as the default.
To run Python in Linux:
A widely used way to run Python code is through an interactive session.
To start a Python interactive session, just open a command-line or terminal and then type in python, or python3 depending on your Python installation, and then hit Enter .
Python comes preinstalled on most Linux distributions, and is available as a package on all others.
However there are certain features you might want to use that are not available on your distro's package.
You can easily compile the latest version of Python from source.
Installing Python 3 on Linux:
- To see which version of Python 3 you have installed, open a command prompt and run
$ python3 --version
- If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands:
$ sudo apt-get update
$ sudo apt-get install python3.6
- If you're using another version of Ubuntu (e.g. the latest LTS release) or you want to use a more current Python, we recommend using the deadsnakes PPA to install Python 3.8:
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.8
- If you are using other Linux distribution, chances are you already have Python 3 pre-installed as well. If not, use your distribution's package manager. For example on Fedora, you would use dnf:
$ sudo dnf install python3
To see if pip is installed, open a command prompt and run:
$ command -v pip
https://linuxapt.com/blog/122-install-and-run-python-on-centos-8