1
votes

I have two versions of python installed on my Linux box 2.6 and 2.7, as indicated in the link I have installed python 2.7 in /usr/local/bin/ and have created alias and updated PATH variable. The 2.6 is installed in /usr/bin/.

After this when I check the python version it displays 2.7.3 on terminal but on the same terminal when I run a bash script (that need to detect the python version) it displays as 2.6.

How should I enforce the bash script to refer to alias or /usr/local/bin for picking the right python version.

2
please provide the bash script - piyushj
By default it looks like your script is looking at /usr/bin/python which has to be a symbolic link. Update that link to point to 2.7 directory and it should be all set. - ring bearer
I strongly recommend to use virtualenv - hek2mgl
@Panch you don't need to make changes in script file. Just set the path like I have shown and then run the script. - khrm
Here is the script # Validate the python installed if [[ $(python --version 2>&1) != *2\.7* ]]; then echo -e "$COL_RED Qt compile requires Python 2.7 $COL_RESET"; exit 1 else echo "Detected Python version 2.7" fi - Panch

2 Answers

3
votes

You have an alias in your profile. However, aliases do not carried along when running a script.

So what you need to do is to either use the full path everywhere in the script or to indicate the path in the very beginning.

#!/bin/bash

PYTHON_PATH=/usr/local/bin
MY_PYTHON=$PYTHON_PATH/python2.7.3

And then call it like:

$MY_PYTHON ... things
0
votes

You need to update your PATH. Then you can use, like this:

export PATH="/usr/local/bin:$PATH"

Note I am including usr/local/bin before the other path Include path before it. Include this in ~/.bashrc or ~/.bash_profile so that you don't need to do this every time you open a new shell.