2

I have compiled and installed python2.6 on my system with python2.7 installed as well. Unfortunately, I did not do it correctly and now my default python is 2.6. When I enter

which python && /usr/bin/env python -V

I am given

/usr/local/bin/python
Python 2.6.9

How can I change this? I checked my $PATH variable, but anything relevant to python is not there. The desired version is

/usr/bin/python
user1876508
  • 12,864
  • 21
  • 68
  • 105
  • probably `export PATH=/usr/bin/:$PATH` will do the trick; you may also add a symbolic link to `/usr/bin/python` in the first directory in the `PATH` – behzad.nouri Feb 26 '14 at 23:03
  • I think you can find the solution in [Change default Python version from 2.4 to 2.6](http://stackoverflow.com/questions/3339530/change-default-python-version-from-2-4-to-2-6?rq=1) – Bengt Feb 26 '14 at 23:03
  • If in your `$PATH`, `/usr/local/bin` occurs before `/usr/bin`, `which python` will find `/usr/local/bin/python`. And in the usual setting of `$PATH`, `/usr/local/bin` indeed occurs before `/usr/bin`. – Lee Duhem Feb 27 '14 at 04:35

1 Answers1

0

Ideally, you should NOT change the default python on your systems. Too many things are dependent on it. HOwever, you can install a newer version and use it in your scripts. Here's is an abridged version of how to do this

DOWNLOAD AND INSTALL PYTHON 2.7

The Fedora system comes stock with Python 2.6. As I've learned, you do not want to remove/overwrite 2.6 as other system tools use it. So you will want to install it as an "alternate" version.

First download Python 2.7 from the Python Org download website!. At the time of this writing, the latest release is Python 2.7.6. All of these instructions assume you are doing these as root. You can alternatively use sudo.

NOTE: the final step is to use make altinstall. This is important.

wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar xvzf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/local
make

You can verify the installation:

[root@centos6_4_32 ~]# python2.7 --version

Python 2.7.6
make altinstall

DOWNLOAD AND INSTALL PIP

The pip tool is used to install Python modules (a.k.a. "packages", "libraries", etc.). You need to install the latest set of tools and ensure they are installed in the Python 2.7 area of you system. You do NOT want to use the stock pip tool since it will install in the Python 2.6 area. The following instructions were taken from this website. At the time of this writing, the latest version of pip is 1.4.1.

# copy the setup scripts

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py

# now make sure you use python2.7 when installing
# these tools!

python2.7 ez_setup.py
python2.7 get-pip.py

NOTE: Ensure that you are using python2.7 when running these scripts, and not just python.

You can verify the installation:

[root@centos6_4_32 ~]# pip-2.7 --version
pip 1.4.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

NOTE: use pip-2.7 and not just pip.

Source: http://forums.juniper.net/t5/Network-Automaniac/Installing-Python-2-7-on-CentOS-6/ba-p/217295

user1048839
  • 938
  • 3
  • 9
  • 24