How to Install Python & Set up Programming Environment on CentOS
Python is a very famous and easy language to learn. It is famous for its simple programming syntax, code readability, and English like commands. Also python is the most popular language used by data scientists around the world. There are many features because of which it is popular among the developer’s community as well as in industries.
In this article we will walk through the process of installing python and setting up a programming environment on CentOS.
CentOS is a Linux distribution derived from Red Hat Enterprise Linux. It provides a free, enterprise-class, community-supported computing platform for web hosting servers.
Python comes preinstalled on most of the Linux machines. But if you want to use python3 and that is not installed on Linux machine like CentOS, we need to install it.
- CentOS 8 server
- sudo privileged user
The first thing we will do is to update the default system applications to the latest available versions. For this we will be using the package manager tool yum which stands for Yellowdog Updater Modified. It lets us easily install and update software packages on our system.
To update your system go to terminal and type
$ sudo yum update
You will be prompted to run updates, be sure to run them.
Next we will install yum-utils, a collection of utilities, and plugins.
$ sudo yum install yum-utils
Finally, we will install the development tools, for that you have to type
$ sudo yum groupinstall development
Now we are ready to install python3. As CentOS is derived from Red Hat Enterprise Linux (RHEL), it tries to be stable as it can be. Also the standard yum repositories do not provide the latest Python release.
For that we first need to install the IUS package, which stands for Inline with Upstream Stable, which will get you up to date with their site. You can install IUS by using
$ sudo yum install htpps://centos8.ius.community.org/ius-release.rpm
Now with this package installed, we can proceed to install python3.7
$ sudo yum install python37u
After the installation is complete, we can check if the installation was successful by checking the version.
$ python3.7 -v
If the installation is successful you will get the following output
The next step is to install pip to manage python packages, and some development packages.
$ sudo yum install python37u-pip $ sudo yum install python37u-devel
Creating a Virtual Environment
A virtual environment is nothing but an isolated installation of python and its dependencies that can be used to better manage the dependencies and keep the installation of the package to a minimum per project.
Choose a directory in which you want to put your python programming environments or create a new directory.
$ mkdir virtual $ cd virtual
So now you are in the folder in which you want to create an environment, you can do it using
$ python3.7 -m venv OS
After you run this command, it will create a new directory OS which will contain few items that are essential for our virtualenv.
To use the virtualenv you just created, you need to activate it which can be done by using
$ source OS/bin/activate
And you can see the name of the virtualenv at the start of the prompt, which lets us know that the environment is active.
So we have successfully installed python and set up a programming environment on CentOS.