Agustus 21, 2012

Change Python Interpreter Temporary (python3 -> python2)

I came across this difficulty when I try to install ArangoDB. It comes with V8 Javascript engine from Google bundled in. Installing V8 requires Python 2, not Python 3 which is the default in my Arch Linux box.

[bpdp@bpdp-arch V8]$ ls `which python`
lrwxrwxrwx 1 root root 7 Apr 24 06:48 /usr/bin/python -> python3
[bpdp@bpdp-arch V8]$

Luckily, V8 uses "#/usr/bin/env python", not "#/usr/bin/python". To change this behaviour, all I have to do is just ask "env" to use my python2 interpreter. Here's how:

1. Create symlink to python2 under the name "python"
I put the symlink into my "$HOME/bin" directory.
$ cd ~/bin
$ ln -s /usr/bin/python2 python

2. Put into PATH

$ export PATH=~/bin:$PATH

"~/bin" should preced $PATH because env use the first setting.

[bpdp@bpdp-arch arangodb]$ which python
/home/bpdp/bin/python
[bpdp@bpdp-arch arangodb]$ env python
Python 2.7.3 (default, Apr 24 2012, 00:06:13) 
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

There you go!

0 comments:

Poskan Komentar