1

I am currently able to run .py python scripts from a terminal due, I believe, to this inclusion in my .profile file:

export PYTHONPATH=/home/myplace/python

python being the directory where I put all my home rolled scripts. The thing is that the default interpreter is python 2 and I'd like to be able to run python 3 scripts the same way. Is there a way to indicate in a .py script which interpreter to use? I've seen ample warnings against changing the default interpreter and it's not something I want to do anyway.

TIA

Tony Martin
  • 477
  • 1
  • 5
  • 16
  • Please add your answer as answer not in the body question. See also: http://askubuntu.com/help/self-answer – Radu Rădeanu Sep 26 '13 at 10:11
  • possible duplicate of [How do I change my PYTHONPATH to make 3,2 my default Python instead of 2.7.2?](http://askubuntu.com/questions/103469/how-do-i-change-my-pythonpath-to-make-3-2-my-default-python-instead-of-2-7-2) – Radu Rădeanu Sep 26 '13 at 10:23
  • I don't think it is a duplicate as it is not about changing the default Python version but to use another version for some scripts. – Florian Diesch Sep 26 '13 at 11:34
  • I say specifically in the question that I do not want to change the default interpreter. There are many warnings that this might break certain tools that depend on Python 2. – Tony Martin Sep 26 '13 at 20:51

1 Answers1

2

And to answer my own question for the benefit of anybody else barking up the wrong tree, it's a simple matter of putting the location of the interpreter in a shebang at the top of the script:

#! /opt/python3/bin/python3.x

or some such depending on your particular installation.

Tony Martin
  • 477
  • 1
  • 5
  • 16