Re: How to have python 2 and 3 both on windows?
On 4/23/22, Sunil KR via Python-list wrote: > > 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 `#!py -3` is not a valid shebang for the py launcher. Use `#!python3` to run a script with the highest version of Python 3 that's registered on your system. Or for cross-platform support, use `#!/usr/bin/python3`. > I don't want to put a unix (or for that matter windows) path in the shebang, > as it is not platform portable The launcher supports builtin virtual shebangs, including: * #!python[X[.Y][-32|-64]] * #!/usr/bin/python[X[.Y][-32|-64]] * #!/usr/bin/env python[X[.Y][-32|-64]] * #!/usr/local/bin/python[X[.Y][-32|-64]] The implementation of the `/usr/bin/env` virtual shebang searches PATH for a given command that's exactly "python" (no version spec) or any command that doesn't start with "python". If a "python" command has a version spec, then PATH is not searched, and it works the same as a `#!pythonX[.Y]` shebang. The latter is because a normal Python installation doesn't include versioned executable names, so the launcher doesn't even try to search PATH for something like "python3.11.exe". You can set the default version to use via the PY_PYTHON environment variable, e.g. `set PY_PYTHON=3.9`. If Python 3 is requested without a specific version (e.g. via `py -3` at the command line, or the shebang `#!python3`), then the default 3.x version to run can be set via the PY_PYTHON3 environment variable, e.g. `set PY_PYTHON3=3.10`. The default for Python 2 is set similarly via PY_PYTHON2. The launcher also supports real file paths in shebangs. Generally you'd only use a real path in order to run in a virtual environment, such as #!"C:\Path\to\venv\Scripts\python.exe". -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
On 2022-04-24 01:19:38 +, Sunil KR via Python-list wrote: > 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? You haven't shown us how you invoke those scripts, so we can't answer that question with the information you gave us. hp -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | h...@hjp.at |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
The question is not one of conversion. The question is this: When I have both python 2 and python3, why is my python 2 script breaking? And when I remove python3 the problem goes away? In both cases (regardless of installing python 3 or not) I am using only python 2 to run the python2 script. Why does the installation of python3 affect the python2, and how can I get them to work without stepping on one another? On Saturday, April 23, 2022, 09:59:46 PM PDT, Dennis Lee Bieber wrote: On Sun, 24 Apr 2022 01:19:38 + (UTC), Sunil KR declaimed the following: > >-- 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 python2, the default for strings is BYTES -- you must explicitly ask for unicode (for literals, using u'literal' notation). Python3 strings are, by default, interpreted as unicode (with the encoding for source code [and hence, literals] specified somewhere via a special comment). Getting a normal python2 string requires using the b'literal' notation to indicate /bytes/. Also, in Python2, print is a language statement, not a function. If you have any print statements that do not have ( ) surrounding the output items, it WILL fail in Python3. >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 > Even if you are not "allowed to change" those scripts, have you tried feeding them through the 2to3 conversion script just to see what type of changes would be required? https://docs.python.org/3/library/2to3.html -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
On Sun, 24 Apr 2022 01:19:38 + (UTC), Sunil KR declaimed the following: > >-- 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 python2, the default for strings is BYTES -- you must explicitly ask for unicode (for literals, using u'literal' notation). Python3 strings are, by default, interpreted as unicode (with the encoding for source code [and hence, literals] specified somewhere via a special comment). Getting a normal python2 string requires using the b'literal' notation to indicate /bytes/. Also, in Python2, print is a language statement, not a function. If you have any print statements that do not have ( ) surrounding the output items, it WILL fail in Python3. >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 > Even if you are not "allowed to change" those scripts, have you tried feeding them through the 2to3 conversion script just to see what type of changes would be required? https://docs.python.org/3/library/2to3.html -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
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 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 > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
> On 22 Apr 2022, at 18:43, Gisle Vanem wrote: > > Barry wrote: > >> Tip “py.exe -0” will list the state of installed pythons. > Not here; 'py.exe -0' gives: > Requested Python version (0) not installed > > Which PyInstaller version support this '-0' option? I do not when it was first added all the installs I have done in the last few years have it working. Barry > > -- > --gv > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
On 4/22/22 11:40, Gisle Vanem wrote: > Barry wrote: > >> Tip “py.exe -0” will list the state of installed pythons. > Not here; 'py.exe -0' gives: > Requested Python version (0) not installed > > Which PyInstaller version support this '-0' option? > Looks like this got added around 3.7... https://bugs.python.org/issue30362 -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
Barry wrote: Tip “py.exe -0” will list the state of installed pythons. Not here; 'py.exe -0' gives: Requested Python version (0) not installed Which PyInstaller version support this '-0' option? -- --gv -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
Please excuse the formatting in my previous message. And it is not complete even, so here is the rest of it. What happens after I follow the above steps: - Upon running one of my python 2 scripts (using python2), I see this error: """ ^SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 237-238: truncated \u escape I tried for a bit, but I could not isolate the content of the file that may be causing this problem. But any idea about this problem would be greatly appreciated. Removing python3 solves this issue.. Sunil On Friday, April 22, 2022, 09:09:22 AM PDT, Sunil KR via Python-list 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 -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How to have python 2 and 3 both on windows?
> On 22 Apr 2022, at 17:10, Sunil KR via Python-list > 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 > -- https://mail.python.org/mailman/listinfo/python-list
How to have python 2 and 3 both on windows?
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 -- https://mail.python.org/mailman/listinfo/python-list