Does windows edit .py file shebangs?

Barry Scott barry at barrys-emacs.org
Sun Jan 3 08:49:46 EST 2021



> On 1 Jan 2021, at 17:03, Eryk Sun <eryksun at gmail.com> wrote:
> 
> On 1/1/21, Barry Scott <barry at barrys-emacs.org> wrote:
>> I found python scripts have had their shebang lines edited behind my back.
>> 
>> The shebang line I'm seeing is:
>> 
>>    #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE
>> 
>> Is this Microsoft being "helpful"?
>> Does anyone know what I will have done to best with this "help"?
>> 
>> What do I need to do to prevent this happening?
> 
> Shebang lines may be localized to the current interpreter when
> installing a package. Otherwise I don't know what's causing that.

These are personal scripts not installed from PyPI for example.

> 
> Regarding Windows, the system doesn't support shebang lines in any
> way. Python's installer associates .py files with the py.exe launcher,
> which looks for a shebang line in a script in order to determine which
> executable to run. It supports shebangs with fully-qualified Windows
> paths, as well as virtual commands for registered installations, such
> as "python", "python3", "python3.9-32", "/usr/bin/python3", and
> "/usr/bin/env python".

Indeed since py.exe is the only tool that supports the shebang this is very strange
that the change was made. I rely on py.exe handling shebang for my cross platform
scripts.

I've been doing some more investigation and found that the change happened
at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE.

The files that where changed where all in my %USERPROFILE%\bin
folder that is on my PATH. I manage the files in that folder with tools that
sync the files from an SVN repo. The version of the files in the repo do not
have the edit.

My PATH does not have a PYTHON.EXE or PYTHON3.EXE on it as
I use py.exe.

Is that the path used by the Microsoft store for the python alias?

I have now turned off the alias in the "Manage App execution aliases"
in settings.

I did find this blog post from Steve Dower about the app store python.

https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/ <https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/>

I have also scanned the Windows logs for events at the time stamp from the
file and could not see anything. 

Thinking back to the 1st I did run Visual Studio 2019 Community edition at that time.
It was  first time on a long time and I had to login and update it.

Is Visual Studio doing the change? If so why?

Barry


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



More information about the Python-list mailing list