1

I just start learning Python in my company, I usually type python ext.py to run a script. The default Python version is 2.4. But now I need to run a new script in Python 3.

The company's IT support installed Python 3 in /usr/local/python3.2.3/bin/python3, but when I type python -V to check version, it still shows Python 2.4. The IT support said they can't replace the old version. How can i run the script using Python 3?

1
  • You just need to provide the absolute path to the python interpreter. When you type "python -v" it is finding the default version, or the first version it finds based on your PATH. Commented Oct 17, 2012 at 7:54

3 Answers 3

3

You can modify your PATH environment variable to get python3 picked up first, or create an alias that'll give you a command for running python3.

To modify your PATH edit your shell configuration file (e.g., ~/.bashrc if you are using BASH)

PATH=/usr/local/python3.2.3/bin:$PATH

To create an alias to python3 do (in the same file),

alias python3=/usr/local/python3.2.3/bin/python3

Sign up to request clarification or add additional context in comments.

Comments

1

/usr/local/python3.2.3/bin/python3 -V
/usr/local/python3.2.3/bin/python3 ext.py

Comments

0

As py2 and 3 have so many differences, usually Python 3 will be started with python3 instead of a mere python.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.