Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
Please add your answer as answer not in the body question. See also: – Radu Rădeanu Sep 26 '13 at 10:11
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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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