Prerequisites

  • RHEL 6 or 7 server up and running
  • Sudo or root priviledged user

Install the necessary utilities

Make sure you have the prerequisites

sudo yum update
sudo yum install yum-utils
sudo yum groupinstall development

Install Python 3.6

The standard yum repositories does not the latest Python release (as of this writing), so lets install an additional repository, called IUM (Inline with Upstream Stable) toprovide the necessary RPM packages.

Install IUM repository:

sudo yum install https://centos7.iuscommunity.org/ius-release.rpm

Now install python36

sudo yum install python36u

Check the Python version with (should return Python 3.6.1 at the time of writing):

python3.6 -V

Lets use pip to manage Python packages, and some development packages.

sudo yum install python36u-pip
sudo yum install python36u-devel

Show the versions of python installed

# Return the system Python version
python -V
Python 2.7.5

# Now show Python 3 version
python3.6 -V
Python 3.6.1

Installing pip for python 3.6

# First command requires you to have enabled EPEL for CentOS7
sudo yum install python36-setuptools
sudo easy_install pip

Installing pip on CentOS 7 for Python 3.x
Assuming you installed Python 3.4 from EPEL, you can install Python 3’s setup tools and use it to install pip.

# First command requires you to have enabled EPEL for CentOS7

sudo yum install python34-setuptools
sudo easy_install pip

# use which "pip3.6" and "which python3.6" to find the path, yes it should be in bin
# unfortunately - lots of stuff depends on the old version, we cannot remove the old, so we have to explicitly state pip3.6 and python3.6
[root@lamp74 bin]# /bin/pip3.6 --version
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
[root@lamp74 bin]# /bin/python3.6 --version
Python 3.6.4

If your Unix/Linux distro doesn’t have it in package repos then install using the manual way detailed below.

The manual way to install pip3.6

If you want to do it the manual way, the now-recommended method is to install using the get-pip.py script from pip’s installation instructions.

Install pip

To install pip, securely download get-pip.py

Then run the following (which may require administrator access):

python get-pip.py

If setuptools is not already installed, get-pip.py will install setuptools for you.

Creating a virtualenv – isolate your project with a specific version of python

The preferred way to create a new virtualenv in Python 3 is to run (in your project directory):

python3.6 -m venv myvenv

To activate the virtualenv and start installing packages with pip:

. venv/bin/activate
pip install [package_name]
pip install -r requirements.txt

More from lonzodb on linux here

Leave a Reply

Your email address will not be published. Required fields are marked *