close

How to change python version in command prompt if I have 2 python version installed

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to change python version in command prompt if I have 2 python version installed in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

How to change python version in command prompt if I have 2 python version installed?

  1. How to change python version in command prompt if I have 2 python version installed?

    If you want to run Python 3.6, then execute python3.6. Otherwise, check with which python where the symbolic link to the actual python executable is.

  2. change python version in command prompt if I have 2 python version installed

    If you want to run Python 3.6, then execute python3.6. Otherwise, check with which python where the symbolic link to the actual python executable is.

Method 1

You should have python3 also in your path. You could use python3 to run your script:

python3 <your_script>

But to answer your question, you could use alias and update it as python.

$ python --version    
Python 2.7.6
$ alias python=python3
$ python --version    
Python 3.6.4

Method 2

If you want to run Python 3.6, then execute python3.6. Otherwise, check with which python where the symbolic link to the actual python executable is. On my system, it’s

/usr/bin/python

and when I ls -la /usr/bin/python, it gives

lrwxrwxrwx 42 user user 42 Aug 24 03:45 /usr/bin/python -> python2.7

If you are really sure that you want to do it, you can now just move the old symlink somewhere:

sudo mv /usr/bin/python /usr/bin/old_python

and create a new symlink:

sudo ln -s /usr/bin/python3.6 /usr/bin/python

Now you should get something like:

$ python --version
Python 3.6.5

I don’t guarantee that it doesn’t break everything in the world, especially if you have some distro that has a package manager that relies on a specific python version under python.

This seemed to work nicely on Linux Mint 18.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read