0

I have the following in my shell script ,i have a python version present in /prj/qct/asw/SA/Linux which is overwriting the default one /usr/bin/python,how do I ensure python version is picked from /usr/bin/python with still exporting the KWTOOLS_DIR ?

export KWTOOLS_DIR=${KWTOOLS_DIR:-"/prj/qct/asw/SA/Linux"}
export PATH=${KWTOOLS_DIR}/Klocwork/Server/bin:$PATH 
ossek
  • 1,638
  • 17
  • 25
user3131197
  • 111
  • 1
  • 6

1 Answers1

1

You can ensure that the path of your python installation appears earliest in the PATH,

export KWTOOLS_DIR=${KWTOOLS_DIR:-"/prj/qct/asw/SA/Linux"}
export PATH=$PATH:${KWTOOLS_DIR}/Klocwork/Server/bin 

or you could use environment management tools such as virtualenv. I'd suggest the latter as it helps you isolate your python installations and the various dependency sets you might have for a given python install or version.

You can also start your individual scripts with the version you want to use:

#! /usr/bin/python

More detail on that route is here

other questions posed slightly differently but that might have the same answers:

regarding usr/bin/env

usage of #!

more usage of #!

Community
  • 1
  • 1
ossek
  • 1,638
  • 17
  • 25
  • how to ensure the path of your pythoninstallation appears firt..can we do export on the path before the KWTOOLS_DIR ?please suggest exact script changes – user3131197 Feb 28 '14 at 21:17
  • edited with script adjustment. append to end instead. – ossek Feb 28 '14 at 21:19
  • this super user question might be helpful as well: http://superuser.com/questions/238987/how-does-unix-search-for-executable-files – ossek Feb 28 '14 at 21:26
  • willthe following work?export KWTOOLS_DIR=${KWTOOLS_DIR:-"/prj/qct/asw/SA/Linux"} export PATH=$PATH:${KWTOOLS_DIR}/Klocwork/Server/bin export PATH=$PATH:/usr/bin/python – user3131197 Feb 28 '14 at 21:31
  • I'm not sure why you're trying to append `/usr/bin/python` to the end of the path; `/usr/bin` should already be on your path. And if it wasn't then this puts `/usr/bin/python` after the `KWTOOLS_DIR`. – ossek Feb 28 '14 at 21:34