1

I have installed both versions of python that is python 2.7 and python 3.5.3. When I run python command in command prompt, python 3.5.3 interpreter shows up. How can I switch to python 2.7 interpreter?

4
  • 1
    have you tried running the command python2? Commented Mar 3, 2017 at 15:47
  • python command will run your python 2.7 and python3 command will run your python 3.5.3 Commented Mar 3, 2017 at 15:52
  • My problem is solved now. I am using win10. I m using py -2 or py -3 to switch different versions of python. Commented Mar 3, 2017 at 16:04
  • 2
    @AnilSoren: Welcome to StackOverflow! The usage here is to accept the answer that you find the most useful to clearly state that this question was answered and you no longer need help on it. Commented Mar 3, 2017 at 16:08

7 Answers 7

1

Usually on all major operating systems the commands python2 and python3 run the correct version of Python respectively. If you have several versions of e.g. Python 3 installed, python32 or python35 would start Python 3.2 or Python 3.5. python usually starts the lowest version installed I think.

Hope this helps!

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

Comments

1

Solution for unix like OS.

You can use python2 and python3 to run certain version of Python

Also, you can check where are these files:

which python2
which python3

2 Comments

the title said cmd so it must be windows :/
He changed the title, dummy
1

As has been mentioned in other answers to this and similar questions, if you're using Windows, cmd reads down the PATH variable from the top down. On my system I have Python 3.8 and 3.10 installed. I wanted my cmd to solely use 3.8, so I moved it to the top of the PATH variable and the next time I opened cmd and used python --version it returned 3.8.

Hopefully this is useful for future devs researching this specific question.

Comments

0

In my case, /usr/bin/python is a symlink that points to /usr/bin/python2.7.

Ususally, there is a relevant symlink for python2 and python3.

So, if you type python2 you get a python-2 interpreter and if you type python3 you get a python-3 one.

Comments

0

If you use Windows OS:

py -2.7 for python 2.7

py -3 for python 3.x

But first you need to check your PATH

Comments

0

It depends on OS (and the way Python has been installed).

For most current installations:

  • on Windows, Python 3.x installs a py command in the path that can be used that way:

    • py -2 launches Python2
    • py -3 launches Python3
  • On Unix-likes, the most common way is to have different names for the executables of different versions (or to have different symlinks do them). So you can normally call directly python2.7 or python2 to start that version (and python3 or python3.5 for the alternate one). By default only a part of all those symlinks can have been installed but at least one per version. Search you path to find them

Comments

0

However, what you can do, is create an alias for your personal use. This can be accomplished easily by adding the following line:

alias python=python3

or

alias python=/usr/bin/python3

/in the ~/.bash_aliases file - which you can edit via sudo nano ~/.bash_aliases. Then, close and reopen the terminal and you should be able to use the python command for your own personal use without it affecting the rest of the system.

However, this, again, isn't suggested because although you won't break any of the system-wide code that relies on proper placement of Python interpreters, I've heard it can cause other issues (that I don't know/remember.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.