1. Home
  2. Linux
  3. How to Compile and Install Python3.5 and Python-pip from Source on CentOS

How to Compile and Install Python3.5 and Python-pip from Source on CentOS

Hi, I recently followed your guide to install Python-pip on my CentOS Box. As you had told in the article, ‘yum install python-pip‘ didn’t work, probably I need to configuring another yum repository. Anyway I tried wget https://bootstrap.pypa.io/get-pip.py and install it via ‘python2.4 get-pip.py‘ command. Unfortunately, the command exited with an error message as ‘SyntaxError: invalid syntax‘ at line 43.

Here is the complete error message:

$python2.4 get-pip.py
 File "get-pip.py", line 43
 _b85alphabet = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 ^
 SyntaxError: invalid syntax

What could be the problem?

Another Solution for Python PiP installation : How to install Python pip on CentOS/Debian/Ubuntu

Solution:

First of all, thanks for referring our article and also letting us know that the steps mentioned didn’t work for you. Sorry about that. However, I try my best to help you in solving the error.

According to the snippet you had posted, I understand that you are using Python version 2.4. I just googled around and it seems like Pip no longer supports Python 2.4. So upgrading python might help.

Install python via yum

$ yum install python3.5

In case, if yum didn’t work for you, then you may download Python source and compile it as below:

How to Install Python3.5 (which will support Python-pip as well)

Install python pip

Download Python source

$wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz

Extract Python package:

$tar xf Python-3.5.0.tar.xz

In case, if ‘tar‘ didn’t support ‘xz‘ file format, then you need to ‘yum update tar‘. Else refer this guide to install xz extractor.

If you are using ‘xz‘ command to extract ‘Python-3.5.0.tar.xz‘, then below is the command:

$xz -d Python-3.5.0.tar.xz

Now you have Python package extracted. Install it as below:

$cd Python-3.5.0

Compile Python:

$./configure

Make:

$make

Install:

$make install
 ::::::::::::::::::::::::::
 Installing collected packages: setuptools, pip
 Successfully installed pip-7.1.2 setuptools-18.2

Check Python version:

$which python3.5
 /usr/local/bin/python3.5

As you see from the above output, Python3.5 will install Pip as well. Check for pip executable as below:

$whereis pip
 pip: /usr/local/bin/pip3.5

Now you have Python-pip command installed.

$pip3.5

Create symbolic link as below:

$ln -s /usr/local/bin/pip3.5 /usr/local/bin/pip

That’s it.

Updated on September 2, 2017

Was this article helpful?

Related Articles

Leave a Comment