I followed the directions for setting a default python version and changed my .bash_profile to: # .bash_profile alias python=python2.7 # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH If I do "python -V" via ssh I get "Python 2.7.1" But if I create a script test.sh: #!/bin/sh echo `python -V` when I execute it, the output is "Python 2.4.3". Is my .bash_profile incorrect, or is there something else I must do to get scripts to default to Python 2.7? asked 28 Jul '11, 16:54 crosseyedpen... |
The issue here is the script is set up to use 'sh' which is a different shell than 'bash', so any settings you put in .bash_profile will not be detected in sh. To correct this you can do a number of things,
answered 28 Jul '11, 17:37 johns I created .profile with the contents: alias python=python2.7 and then did: source ~/.profile But when I executed my test.sh I still received "Python 2.4.3" So I tried again adding the file .sh_profile. Same results. When I do a "ls -l /bin", a portion of the response shows sh is linked to bash. -rwxr-xr-x 1 root root 20688 Jan 9 2007 setserial lrwxrwxrwx 1 root root 4 May 17 11:01 sh -> bash -rwxr-xr-x 1 root root 19692 Mar 30 12:12 sleep I also tried changing my test.sh script to: #!/bin/bash echo `python -V` But this yielded the same results. Executing the script yields "Python 2.4.3". Finally, I did try changing my test.sh to: #!/bin/bash echo `python2.7 -V` This did yield "Python 2.7.1". However, I am trying to use some complex scripts that someone else wrote -- fixing these appears to be much harder than replacing every "python" with "python2.7". Is there an easier way to make Python 2.7 my default all the time?
(28 Jul '11, 19:57)
crosseyedpen...
I tried a few things but found that creating this symlink is the easiest way,
(28 Jul '11, 20:20)
johns
hmmm. Seems like the above should work, but I am still getting "Python 2.4.3". My ~/bin after the change: [rockart@web201 bin]$ ls -l total 16 -rwxrwxr-x 1 rockart rockart 1070 Jul 19 15:57 hg -rwxr-xr-x 1 rockart rockart 250 Jul 18 17:23 pip -rwxr-xr-x 1 rockart rockart 258 Jul 18 17:23 pip-2.7 lrwxrwxrwx 1 rockart rockart 24 Jul 28 22:05 python -> /usr/local/bin/python2.7 -rwxr-xr-x 1 rockart rockart 285 Jul 18 17:25 virtualenv And my test.sh changed back to the original above: #!/bin/sh echo `python -V`
(28 Jul '11, 22:27)
crosseyedpen...
Submit a support ticket so we can look directly.
(28 Jul '11, 22:35)
johns
For the record, the docs at http://docs.webfaction.com/software/python.html#creating-a-python-alias were updated to remove the reference to a "default" python and note that a python "alias" is not available within shell scripts.
(31 Jul '11, 12:16)
crosseyedpen...
|
I've had the same problem. To fix it, first thing to do is to make ~/bin more priority path, so changed in ~/.bash_profile: PATH=$HOME/bin:$PATH and then of course followed the advice from johns and created symlink: ln -s /usr/local/bin/python2.7 ~/bin/python answered 31 Aug '11, 15:31 avk |