Verified and Tested 02/26/15
This article covers the installation of Python 3.4 on a CentOS 6.7 operating system and how to create a Virtual Environment(venv) with pyvenv for which Python 3 can run. It is important to note the directories that we are installing is Python 3.4. CentOS 6.x is dependent on Python 2.x to function properly, do not overwrite the Python 2 installation accidentally. If you still need to install Python 2, follow our how-to on this here.
You’ll need to yum install the following packets to meet all the Python 3 and PIP dependencies:
– You need a CentOS 6.7 server. If you do not have a server already, you can spin up a dependable cloud server from Atlantic.Net in under 30 seconds.
– “Development Tools” “Development Libraries”
Installing Python 3 from source on CentOS 6.7
Install build tools
yum groupinstall "Development Tools" "Development Libraries"
Install readline-devel so that your keyboard arrow keys work when entering the Python3 interactive terminal
yum -y install readline-devel
Install OpenSSL-devel for pip3
yum -y openssl-devel
Download Latest source code from Python, at the time of writing
Unpack and enter Python-3.4.3 directory
tar xzvf Python-3.4.3.tgz
Build compile environment
make && make install
Creating a Virtual Environment in CentOS 6.7
You’ll see that Python3 has been installed into /opt/python3.4.3. Note that by installing Python3, you have not altered anything with your original python. This is done purposely, if you install Python3 on top of your current Python2.x installation, you’ll break your operating system. This is why we are going to build a Virtual Environment for which we can run python3. This allows you to make changes to your Python3 installation without altering the OS’s version of python3. This is useful if different apps require different versions of Python. It also keeps you from accidentally overwriting your OS’s Python2 files.
Use the Python3 script called pyvenv locate in /opt/python3.4.3/bin/ to create your environment. We’ll create our environment in /home/ and call it py3venv, it will be created automatically if it doesn’t already exist.
To start and/or enter into your virtual Python3 environment execute the following. Your command shell will change to reflect that you are in your virtual environment.
(py3venv) [[email protected]]#
Once inside the virtual environment, you may use PIP to install any additional packages you may require without affecting the system-wide instance of your Python 3 installation.
To exit the virtual environment perform the following to drop back into your normal shell:
(py3venv) [[email protected]]# deactivate
Thank you for following along and feel free to check back with us for further updates or learn more about our reliable cloud hosting servers.