Install Python 3 locally under /home directory in CentOS 6.4

First off, why would you want to install local Python 3? There could be many reasons, some of which may be:

  • You don’t want to touch the system-installed Python
  • You don’t have root privileges
  • You want to run your private/personal scripts without affecting other users on the system
  • You want to run multiple versions of Python not available on your system

For whatever the reasons you want to install Python locally in your home directory, it’s not as difficult as I had first thought it to be. This is a good alternative especially since Python3 is not officially available in CentOS 6.4.

There are four major steps:

  1. Install Development Tools
  2. Download Python Source Code
  3. Compile and Install Python
  4. Modify your $PATH

Install Development Tools

You will need some tools to compile Python. The easiest way to obtain them in CentOS is to install the ‘Development Tools’ group.

cg@codeghar [~] $ su -c 'yum groupinstall "Development Tools"'

You also need some libraries that Python uses to provide “batteries included” support.

cg@codeghar [~] $ su -c 'yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel'

Download Python Source Code

Head over to and download the version you want to install. For this post I used Python 3.3.2.

cg@codeghar [~] $ curl -O

Now just un-tar the file so you can use its contents.

cg@codeghar [~] $ tar xvf Python-3.3.2.tar.bz2

You should see these two items in your home directory:

cg@codeghar [~] $ ls

Python-3.3.2  Python-3.3.2.tar.bz2

Compile and Install Python

You now have Python source and tools to compile it. Change directory to the un-tar’ed source code.

cg@codeghar [~] $ cd Python-3.3.2

Run configure.

cg@codeghar [~/Python-3.3.2] $ ./configure

Create a directory where you will install your local Python.

cg@codeghar [~/Python-3.3.2] $ mkdir -p ~/usr/local

Compile and install Python to the directory you just created.

cg@codeghar [~/Python-3.3.2] $ make altinstall prefix=$HOME/usr/local exec-prefix=$HOME/usr/local

Modify your $PATH

You now want to add ~/usr/local/bin to your $PATH so you don’t have to enter the full path to the Python binary every time you want to use it. Change directory to where local Python binary is located.

cg@codeghar [~/Python-3.3.2] $ cd ~/usr/local/bin

Create an alias so you can refer to it as python3. This is optional but I like to do it because I can then use python to refer to the Python that came with CentOS and python3 to refer to my locally installed Python3.

cg@codeghar [~/usr/local/bin] $ ln -s python3.3 python3

Now add this path to your $PATH environment variable. Notice that we add the new path before existing $PATH. This is so that our local Python is always used before any other.

cg@codeghar [~/usr/local/bin] $ echo "export PATH=\$HOME/usr/local/bin:\$PATH" >> ~/.bashrc

When you open a new terminal window, or log off and then log on, or (even better) run source ~/.bashrc, you can run the following commands to see that your local Python is now on your path.

cg@codeghar [~] $ which python3.3


cg@codeghar [~] $ which python3


cg@codeghar [~] $ which python


You can even run your local Python.

cg@codeghar [~] $ python3

Python 3.3.2 (default, Sep 26 2013, 15:30:36) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello World!")
Hello World!


You can now run your local Python. There’s no need to keep the tar file and the source code around. You may want to delete them.

cg@codeghar [~] $ rm -rf ~/Python-3.3.2

cg@codeghar [~] $ rm ~/Python-3.3.2.tar.bz2

Another thing to consider is virtual environments, virtualenv or venv (in Python 3). Since Python3 comes with its built-in venv, just create an alias for its binary as well.

cg@codeghar [~] $ cd ~/usr/local/bin

cg@codeghar [~/usr/local/bin] $ ln -s pyvenv-3.3 pyvenv

There’s one more modification you need to make to get pyvenv to work. Open the file and change the path to your locally installed Python.

cg@codeghar [~/usr/local/bin] $ vim pyvenv-3.3

Original line is:


After changing it should look something like:


You can now use this local pyvenv to create your virtualenvs.

Hat Tips

How to install locally python on linux home directory?; Installing Python 3 on CentOS/Redhat 5.x From Source; UNIX / Linux: Set your PATH Variable using set or export command; .bash_profile vs .bashrc; RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers

Comments are closed.

%d bloggers like this: