Changing the alias unfortunately does not work. I have changed the alias to alias python='/usr/bin/python2.7' however the shell script still runs the python script in 2.4.3.

Muru - I am using PYTHONPATH to direct to the python path. However as you said this may not be correct. Is there a version of PYTHONPATH that can be used to direct to the a specific python executable?

The Shell script is below as requested.

cd ../../../..

export BREVE_CLASS_PATH=/home/user/breve_2.7.2/lib/classes
export PYTHONPATH=/usr/bin/python2.7

cd /home/user/breve_2.7.2

./bin/breve /home/user/breve_2.7.2/demos/Getting-Started/RandomWalker_version.py

I am running a shell script that runs a python script in a certain program.

My problem is the python script is being launched in python 2.4 whereas I need it to run in python 2.7. In the shell script I have added the following line to try to enforce python2.7 to be used.

export PYTHONPATH=/usr/bin/python2.7

However when the python script prints what version it is using I get python 2.4.3. Am I going the correct way about this?

How should I proceed?

  • Please edit your question and add the mentioned shell script.. – heemayl Apr 15 '15 at 14:30
  • 1
    IIRC PYTHONPATH is not the path to the python executable but the path to python modules. What does the shebang of the python script contain? – muru Apr 15 '15 at 18:44
  • What is the output of head -1 /home/user/breve_2.7.2/bin/breve /home/user/breve_2.7.2/demos/Getting-Started/RandomWalker_version.py? – muru Apr 16 '15 at 9:39
  • This line launchs a program called "breve" that runs a python script called "RandomWalker_version.py". Breve runs the script using python 2.4.3 however I want to run it using 2.7. – Slimjimmy Apr 16 '15 at 9:54
  • 1
    Muru I have added the shebang "#!/usr/bin/python2.7" to the script however 2.4 is still being used. – Slimjimmy Apr 16 '15 at 12:31

Since you have multiple python versions installed and you want to determine which python is to be used as default, you should use update-alternatives command which maintains symbolic links determining default commands.

First of all run this:

update-alternatives --list python

If the result is:

update-alternatives: error: no alternatives for python

Then you should use update-alternatives to --install alternatives of the various python versions that you have (if the --list option resulted in listing alternatives, jump straight to the --config option mentioned later). Parameters for the --install option are group, target and priority where the greater priority number results into higher priority and group means the path of the command that will be given a group of alternatives:

update-alternatives --install /usr/bin/python python /usr/bin/python2.4 1
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2

After this, python 2.7 is your default python since it was given a greater priority number and you have both python versions installed as alternatives (or more if you installed other versions too). Bear in mind that python 2.7 is now the default python for everything.

You can now list the installed alternatives again for a group with --list parameter:

update-alternatives --list python


And now you can switch between the alternatives with:

update-alternatives --config python

Enter the selection number and you're all set to have the desired version of python used as the default python.

Use man pages to read more about update-alternatives:

man update-alternatives
  • I have changed the update-alternatives as requested to give python2.7 priority over other versions however, when I run the script through the breve binary, its still defaults to the python 2.4.3 interpreter. Any other ideas? – Slimjimmy Apr 21 '15 at 9:01
  • This is starting to sound like Breve uses its own python interpreter internally or it directly explicitly fires up python2.4 binary as its interpreter - most likely it's using its own interpreter. Right now I'd contact Breve author if I were you (spiderland.org/breve/documentation.php). Consult back here if you gain any insight. – Ahti Komu Apr 22 '15 at 7:43

Why don't just do

python /home/user/breve_2.7.2/demos/Getting-Started/RandomWalker_version.py 

in the last line. That should solve it (when the shebang is correct).

  • Notice that the script file is an argument for breve binary (en.wikipedia.org/wiki/Breve_%28software%29). Therefore the script doesn't launch the python interpreter. It might be that the binary uses default python interpreter internally for executing scripts. At least that is my impression since shebang isn't working in this case. – Ahti Komu Apr 18 '15 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.