This article is a revisit to a previous article dating back a little over an year, in which I installed Python 3.5.1 from sources. This time I will install Python 3.6.1 from a yum repository.
Same as the last time, CentOS 7 still has Python 2.7 installed out of the box and is used by the system itself to enable the system commands, so let's not mess with that installation.
Although as a developer I can do a lot with Python 2.7, I really want to utilize the new language features which comes with Python 3. Since Python 3.6 come out in the end of last year, we got even more goodies, such as Literal String Interpolation, or the f-strings, as they are called.
Let's get started. By the way, this does not break the installation I made in the previous article, so no worries, if you are on the same server installation as the last time.
- CentOS 7 server up and running
- Sudo priviledged user
As all Linux tutorials out there, first thing is to install the updates. Then I can proceed with the installation of the necessary tools and utilities.
sudo yum update sudo yum install yum-utils sudo yum groupinstall development
Now all of the necessary packages have been installed.
The standard yum repositories does not yet provide the latest Python release, so I need to install an additional repository, called IUM (Inline with Upstream Stable), which provides the necessary RPM packages.
So, to install IUM repository:
sudo yum install https://centos7.iuscommunity.org/ius-release.rpm
Now with the repository installed, I can proceed to install Python 3.6:
sudo yum install python36u
Now it's time to check the Python version with (should return
Python 3.6.1 at the time of writing):
Next up, is pip to manage Python packages, and some development packages.
sudo yum install python36u-pip sudo yum install python36u-devel
Ready to test:
# This should return the system Python version python –V # output: Python 2.7.5 # This should return the Python 3 version python3.6 –V # output: Python 3.6.1
That's it. Now I have Python 3.6 ready to run my apps!
The preferred way to create a new virtualenv in Python 3 is to run (in your project directory):
python3.6 -m venv venv
... where the former
venv is the command to create a virtualenv, and the latter
venvis the name of the virtualenv.
To activate the virtualenv and start installing packages with pip, run:
. venv/bin/activate pip install [package_name] pip install -r requirements.txt