How to have python 2 and 3 both on windows?

Sunil KR krlinus at yahoo.com
Sat Apr 23 21:19:38 EDT 2022


I am happy with how the python starts up. When I use
python
I get python 2. 
I am ok with using py -3 for my new scripts, even using the shebang like
#!py -3
I don't want to put a unix (or for that matter windows) path in the shebang, as it is not platform portable
But the real question/s for me is/are

-- Why are my strings being sent to python3, so that I get the unicode related error?
-- in other cases I see error pertaining to the print function
In my case, I don't own the python2 scripts and so I am not allowed to change any part of them. And I wouldn't need to either, if I can make python 2 and 3 coexist on my system


   > On 22 Apr 2022, at 17:10, Sunil KR via Python-list <python-list at python.org> wrote:
> 
> I have some scripts that are old and won't work under python2 and at the same time I am writing new scripts which will use python3. However, if python 2 and 3 cannot co-exist in a windows box it will be impossible to transition
> What I try:- remove all pythons and launchers- Use windows installer and install python2 in python27 directory- Use windows installer and install python3 in python310 directory- When installing python3 I opt in to install the launcher- Test with py -2 and py -3 and see that I get the expected prompt- just typing python gets me python2

As you have proved you can install many versions of python at the same time on windows.

In your scripts set the shebang to run the python version you want.
E.g
#!/usr/bin/python2
Or
#!/usr/bin/python3

The python launcher py.exe will then do the right thing after looking at en shebang line.

Also you can edit the INI file of the py.exe launcher to set the defaults the way you want them. Do a search for “py.exe ini” to file the path to the file, I do not have it my finger tips.

Tip “py.exe -0” will list the state of installed pythons.

Barry

> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

  


More information about the Python-list mailing list