AntiGMO
AntiGMO

Reputation: 1587

How to run a script with a different version of Python

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?

Upvotes: 1

Views: 476

Answers (3)

glglgl
glglgl

Reputation: 91139

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

Upvotes: 0

user1521446
user1521446

Reputation: 56

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

Upvotes: 3

Robus
Robus

Reputation: 8269

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

Upvotes: 1

Related Questions