Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"py.ini" question

553 views
Skip to first unread message

Gisle Vanem

unread,
Apr 24, 2021, 10:23:31 AM4/24/21
to
I have a question about the Python launcher;
c:\Windows\py.exe and the py.ini file.

I have both Python 3.6 (32-bit) and Python 3.8 (64-bit)
installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini'
with this only:
[defaults]
python=3.6

A copy of this is also in 'c:\Windows\py.ini'.
So when I do a:
py -3 -c "import sys; print(sys.version)"

I would assume a "3.6..." would be printed.
But no, py.exe chooses to run my newest Python 3.8:
3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)]

Only when I do 'py -3.6 -c ...', I get what I'd expect.

So is a 'py.ini' and the '[defaults]' simply ignored
or is my syntax wrong?

--
--gv

Mats Wichmann

unread,
Apr 24, 2021, 11:34:57 AM4/24/21
to
You could try this:

"If an environment variable PYLAUNCH_DEBUG is set (to any value), the
launcher will print diagnostic information to stderr (i.e. to the
console). While this information manages to be simultaneously verbose
and terse, it should allow you to see what versions of Python were
located, why a particular version was chosen and the exact command-line
used to execute the target Python."

and see what it teaches you...

Barry Scott

unread,
Apr 24, 2021, 2:05:39 PM4/24/21
to


> On 24 Apr 2021, at 15:23, Gisle Vanem <gisle...@gmail.com> wrote:
>
> I have a question about the Python launcher;
> c:\Windows\py.exe and the py.ini file.
>
> I have both Python 3.6 (32-bit) and Python 3.8 (64-bit)
> installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini'
> with this only:
> [defaults]
> python=3.6
>
> A copy of this is also in 'c:\Windows\py.ini'.
> So when I do a:
> py -3 -c "import sys; print(sys.version)"
>
> I would assume a "3.6..." would be printed.
> But no, py.exe chooses to run my newest Python 3.8:
> 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)]
>
> Only when I do 'py -3.6 -c ...', I get what I'd expect.
>
> So is a 'py.ini' and the '[defaults]' simply ignored
> or is my syntax wrong?

You can find out what py.exe is using for its config by running:

py -0

The entry with an * at the end is the default.

On windows 10 your personal py.ini is in %localappdata%\py.ini
do you have one?

type %localappdata%\py.ini

If not you might want to create one that sets things up as you need them configured.

Here is what I have on my windows 10:

C:\Users\barry>py -0
Installed Pythons found by py Launcher for Windows
-3.10-64
-3.10-32
-3.9-64 *
-3.9-32
-3.8-64
-3.8-32
-3.7-64
-3.7-32
-3.6-64
-3.6-32
-3.5-64
-3.5-32
-3.4-64
-3.4-32
-2.7-64
-2.7-32


C:\Users\barry>type %localappdata%\py.ini
[defaults]
python=3.9-64
python3=3.9-64

C:\Users\barry>py
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Barry


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

Gisle Vanem

unread,
Apr 24, 2021, 3:56:30 PM4/24/21
to
Barry Scott wrote:

>> A copy of this is also in 'c:\Windows\py.ini'.
>> So when I do a:
>> py -3 -c "import sys; print(sys.version)"
>>
>> I would assume a "3.6..." would be printed.
>> But no, py.exe chooses to run my newest Python 3.8:
>> 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)]
>>
>> Only when I do 'py -3.6 -c ...', I get what I'd expect.
>>
>> So is a 'py.ini' and the '[defaults]' simply ignored
>> or is my syntax wrong?

> On windows 10 your personal py.ini is in %localappdata%\py.ini
> do you have one?

Yes, that's my 'c:\Users\Gisle\AppData\Local\py.ini'
in my case.

> C:\Users\barry>py -0
> Installed Pythons found by py Launcher for Windows
> -3.10-64
> -3.10-32
> -3.9-64 *
> -3.9-32
> -3.8-64
> -3.8-32
> -3.7-64
> -3.7-32
> -3.6-64
> -3.6-32
> -3.5-64
> -3.5-32
> -3.4-64
> -3.4-32
> -2.7-64
> -2.7-32

On that, I'm getting:
Requested Python version (0) not installed

Is that '-0' some 3.9+ feature?

> C:\Users\barry>py
> Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
With a 'py', I get:
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32

With 'py -3.6' or 'py 3.8' I get the expected.
But with 'py -3':
Python 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] on win32

Since I'm on a 64-bit Python, a 'py -3' totally seems to ignore
'py.ini', unless it says:
[defaults]
python3=3.6
python3=3.6-32

Strange as always.

And yes, Mats Wichmann, I've tried a 'set PYLAUNCH_DEBUG=1'.
No help.

--
--gv

Chris Angelico

unread,
Apr 24, 2021, 4:58:01 PM4/24/21
to
On Sun, Apr 25, 2021 at 5:57 AM Gisle Vanem <gisle...@gmail.com> wrote:
>
> With 'py -3.6' or 'py 3.8' I get the expected.
> But with 'py -3':
> Python 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] on win32
>
I believe that's because you're asking for "the latest in the 3.x series".

ChrisA

Mats Wichmann

unread,
Apr 25, 2021, 10:31:02 AM4/25/21
to
unless differently described by the ini file, which is what the OP is
trying to do.

I just added a 3.10 alpha to my Windows setup (I don't do my programming
there, so there hadn't been any need), and set up an ini file to leave
3.9 as the default and all works as expected - py -0, py, py -3, py
-3.10 all given me the one I would expect to get based on that setup (-0
shows 3.9-64 starred, despite 3.10-64 being "the latest).

Personally stumped why it's not working for Gisle.

Ralf M.

unread,
Apr 25, 2021, 3:13:02 PM4/25/21
to
I think the problem / misunderstanding is that Gisle put in py.ini only
[defaults]
python=3.6

and expected this to make py -3 start 3.6. However py -3 looks for a key
named 'python3' and, not finding it, uses default behaviour (ignoring
the 'python' key), i.e. starts the most modern stable 3.x.

The py.ini documentation is a bit hard to find in the help file and hard
to understand as the interesting part talks about environment variables
and shebang line commands, not py.ini settings and py.exe parameters.
However, the behaviour is the same in both cases and the relevant
example is:

"If PY_PYTHON=3.1-32, the command python will use the 32-bit
implementation of 3.1 whereas the command python3 will use the latest
installed Python (PY_PYTHON was not considered at all as a major version
was specified.)"

I tried the (rather insane) py.ini
[defaults]
python=3.7
python2=3.8
python4=2.7
and it works as documented (py -3 shows default behaviour as there is no
'python3' in py.ini):

C:\>py
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916
64 bit(AMD64)] on win32
C:\>py -2
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64
bit (AMD64)] on win32
C:\>py -3
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64
bit (AMD64)] on win32
C:\>py -4
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32
bit (Intel)] on win32




Alan Gauld

unread,
Apr 25, 2021, 3:23:33 PM4/25/21
to
On 24/04/2021 15:23, Gisle Vanem wrote:
> I have a question about the Python launcher;
> c:\Windows\py.exe and the py.ini file.
>
> I have both Python 3.6 (32-bit) and Python 3.8 (64-bit)
> installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini'
> with this only:
> [defaults]
> python=3.6

I don't really use python on Windows so don't use this file.

However, based on some of the other responses, what happens
if you don't specify a version? ie. just type

py -c "...

And also what happens if you add an explicit python3 line as
in Barry's example:

[defaults]
python=3.6
python3=3.6

As I say, pure speculation on my part. But if it helps...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


Gisle Vanem

unread,
Apr 26, 2021, 4:13:28 AM4/26/21
to
Ralf M. wrote:

> I think the problem / misunderstanding is that Gisle put in py.ini only
>  [defaults]
>  python=3.6
>
> and expected this to make py -3 start 3.6. However py -3 looks for a key named 'python3' and, not finding it, uses
> default behaviour (ignoring the 'python' key), i.e. starts the most modern stable 3.x.
>
> The py.ini documentation is a bit hard to find in the help file and hard to understand

I totally agree with that.

> I tried the (rather insane) py.ini
>  [defaults]
>  python=3.7
>  python2=3.8
>  python4=2.7
> and it works as documented (py -3 shows default behaviour as there is no 'python3' in py.ini):
>
> C:\>py
> Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit(AMD64)] on win32
> C:\>py -2
> Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
> C:\>py -3
> Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
> C:\>py -4
> Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32 bit (Intel)] on win32

Thank for confirming what I suspected. And as I wrote earlier:
Since I'm on a 64-bit Python, a 'py -3' totally seems to ignore
'py.ini', unless it says:
[defaults]
python3=3.6
python3=3.6-32
-------

Except, I meant "Since I'm on a 64-bit Windows" and
not "Since I'm on a 64-bit Python".

Barry Scott

unread,
Apr 26, 2021, 1:48:46 PM4/26/21
to


> On 24 Apr 2021, at 20:56, Gisle Vanem <gisle...@gmail.com> wrote:
>
> On that, I'm getting:
> Requested Python version (0) not installed
>
> Is that '-0' some 3.9+ feature?

No its a lot older then 3.9 I cannot remember when -0 was first supported
but I've been using -0 for a long long time.

I using the explorer to find c:\windows\py.exe and checked its Properties.
In the Details tar it says that the "Product version" is 3.10.0a5

I think that py.exe gets updated to the highest version.

What does your py.exe show its version as?

Also Are you sure that you are running c:\windows\py.exe?

What happens if you try running c:\windows\py.exe -0?

Barry

Barry Scott

unread,
Apr 26, 2021, 2:06:16 PM4/26/21
to


> On 26 Apr 2021, at 09:13, Gisle Vanem <gisle...@gmail.com> wrote:
>
> Thank for confirming what I suspected. And as I wrote earlier:
> Since I'm on a 64-bit Python, a 'py -3' totally seems to ignore
> 'py.ini', unless it says:
> [defaults]
> python3=3.6
> python3=3.6-32

You can prove that py.ini is ignored by using PYLAUNCH_DEBUG but I think its that you
do not have the config in the py.ini that does what you want.

As an example is here is the output I see:
C:\Users\barry>set PYLAUNCH_DEBUG=1

C:\Users\barry>py.exe -3
launcher build: 32bit
launcher executable: Console
Using local configuration file 'C:\Users\barry\AppData\Local\py.ini'
File 'C:\WINDOWS\py.ini' non-existent
Called with command line: -3
locating Pythons in 64bit registry
locate_pythons_for_key: C:\Python38.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python38.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python27.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python310.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python34.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python35.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python36.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python37.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
HKLM\SOFTWARE\Python\PythonCore\3.8\InstallPath: The system cannot find the file specified.
locate_pythons_for_key: C:\Python39.win64\python.exe is a 64bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locating Pythons in native registry
locate_pythons_for_key: C:\Python38.win64\python.exe: already found
locate_pythons_for_key: C:\Python38.win64\python.exe: already found
locate_pythons_for_key: C:\Python38.win64\python.exe: already found
locate_pythons_for_key: C:\Python38.win64\python.exe: already found
locate_pythons_for_key: C:\Python38.win32\python.exe: already found
locate_pythons_for_key: C:\Python38.win32\python.exe: already found
locate_pythons_for_key: C:\Python38.win32\python.exe: already found
locate_pythons_for_key: C:\Python38.win32\python.exe: already found
locate_pythons_for_key: C:\Python27.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python310.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python34.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python35.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python36.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python37.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: C:\Python39.win32\python.exe is a 32bit executable
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: : The system cannot find the path specified.
locate_pythons_for_key: unable to open PythonCore key in HKLM
found configured value 'python3=3.9-64' in C:\Users\barry\AppData\Local\py.ini
search for Python version '3.9-64' found 'C:\Python39.win64\python.exe'
run_child: about to run 'C:\Python39.win64\python.exe'
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

You can see in the output that it found my py.ini and use the python3=3.9-64 from it.

Barry










































moi

unread,
Apr 26, 2021, 3:12:55 PM4/26/21
to
Le lundi 26 avril 2021 à 20:06:16 UTC+2, Barry Scott a écrit :
>
> As an example is here is the output I see:
> C:\Users\barry>set PYLAUNCH_DEBUG=1
>
Do you know what I’m seeing ?

I’m seeing text which is not displayed correctly (coding of characters).
Can be "cmd.exe", CHCP 850/1252 or "utf-8" or "powershell" with
misc. [Console]::OutputEncoding.

!? ...


moi

unread,
Apr 28, 2021, 10:49:28 AM4/28/21
to
This is really funny and very interesting.
0 new messages