Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
Please add your answer as answer not in the body question. See also: askubuntu.com/help/self-answer –  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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.