6

I would like to install both python 2.7 and python 3.5 on my Windows 10 PC. Both python executables use the same name python.exe.

Is it a good idea to change python.exe to python3.exe as a quick fix for co-existence? Are there any side-effects or other things that I need to be aware?

2
  • Why are you installing both? wiki.python.org/moin/Python2orPython3 Oct 5, 2016 at 1:52
  • I have a variant on this problem - I have both 32 bit and 64 bit versions of python (needed by different programs, for example my 64 bit Z3 can only run under 64 bit python). I would like to have both pythons on my path with different names for the exe's obviously. Any ideas?
    – Motorhead
    Jan 7, 2019 at 3:08

2 Answers 2

14

You don't need to rename anything for co-existence of different versions of Python.

The different versions of python are installed on different folders automatically.

When use the command prompt you can use the commands py2 or py3 to refer to the different versions of python. The next works too:

C:\Users\user1>py -2

and

C:\Users\user1>py -3

This also works with pip2 and pip3 for install new packages.

For more details, you can read this article: Python Launcher for Windows.

8
  • 2
    user16891328: If you have both installed, you can also add a #!/usr/bin/env python2 or #!/usr/bin/env python3 comment as the first line of your scripts and use py scriptname.py to have the correct interpreter executed.
    – martineau
    Oct 5, 2016 at 1:49
  • @martineau This is a Windows question Oct 5, 2016 at 1:50
  • 1
    @cricket_007: I know that. py makes the shebang work on Windows, too.
    – martineau
    Oct 5, 2016 at 1:53
  • @martineau I meant #!/usr/bin/env Oct 5, 2016 at 1:55
  • 2
    @cricket_007: I understood what you meant. See this section of the documentation where it says the the py launcher makes the same thing work on Windows.
    – martineau
    Oct 5, 2016 at 1:58
1

You'll need to run python3 instead of python if that's not obvious. This is definitely, as you described, a "quick fix"

My suggested fix is to use virtualenv and pass in the Python executable you would like to use as so:

virtualenv -p /usr/bin/python3.5 /my/virtualenv/>

1
  • You can change that to wherever your Python 3.5 exe is found.
    – Dan Hoerst
    Oct 5, 2016 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.