Issue running executable on Windows

102 views
Skip to first unread message

Ryan Ma

unread,
Nov 5, 2020, 5:00:19 AM11/5/20
to PyInstaller
Hi, 

We have been building our Python 3.6 application using PyInstaller v3.6. Recently, one user encountered the below error on Windows 10 AMD64 which caused the application to error out.

STATUS: FAILED ERROR: Failed to get address for Py_DontWriteBytecodeFlag

Unfortunately, I cannot replicate the error and the only similar references I have found online are related to docker-compose. In some of those cases, running with administrator permissions resolves the issue but I am not sure if the user can do this.

Do you have any idea about where the issue stems from?
If running with administrator permissions resolves it, do you have any idea on how to package it so that admin permissions are not required?

Thanks,

Ryan

bwoodsend

unread,
Nov 5, 2020, 10:12:33 AM11/5/20
to PyInstaller

Hmm, gross.

I can see exactly where in PyInstaller’s code this error is being raised. Here it tries to locate this Py_DontWriteBytecodeFlag configuration variable, and following through to the definition of the DECLVAR() macro here you can see the error being raised. I notice the docs for the flag disappears if you rewind back to Python 3.6 but that flag must still be there or everyone would be experiencing issues with Python 3.6. And I can confirm that it’s still present in my python36.dll using:

import ctypes
print(ctypes.POINTER(ctypes.c_int).from_address(ctypes.addressof(ctypes.pythonapi.Py_DontWriteBytecodeFlag)).contents)

which would raise an AttributeError if it didn’t exist (otherwise prints 1 if running Python with the -B option).

What I really don’t understand is why only this one user is seeing it. The only thing I can think of is said user has another incompatible copy of python36.dll in PATH which is being read instead. Could you ask them to run where python* in the command prompt and tell you if there’s anything else there? Could you also build a simple print("hello") app in --onedir mode using your environment and upload it somewhere I can inspect it?

Brénainn

Ryan Ma

unread,
Nov 9, 2020, 3:06:31 AM11/9/20
to PyInstaller
Hey Brénainn,

Thanks for taking a look at this issue. I did find that path of where it locates the flag and then where the error is raised but was unable to progress past that.

I will try and get them to run that command to see if there is anything else there. Separately, they did confirm that the same executable works on a different computer, but the error is surfacing on the more restricted Windows environment they would use in production.

Here's a simple app per your request that just prints "hello" built in `--onedir` mode with the same build environment: https://drive.google.com/file/d/1523gS8W7bJIqApzAXk_4W9gRevwbfZs9/

Regards,

Ryan

Ryan Ma

unread,
Nov 9, 2020, 3:06:34 AM11/9/20
to PyInstaller
Hey Brénainn,

Thanks for looking into this issue. I tried replying earlier but it hasn't showed up for some reason so I'm re-answering.

I had followed that same path into the flag variable and the macro that raises the error but didn't get past that.

I'll try asking the user to run that command to check for an incompatible copy of the dll. They also mentioned that the same executable worked on their computer but failed on the more restrictive windows environment they would be using for production.

Here's a link to the simple app built in `--onedir` mode to just print hello: https://drive.google.com/file/d/1523gS8W7bJIqApzAXk_4W9gRevwbfZs9/view?usp=sharing

Regards,

Ryan

On Thursday, November 5, 2020 at 7:12:33 AM UTC-8 bwoodsend wrote:

bwoodsend

unread,
Nov 9, 2020, 1:05:34 PM11/9/20
to PyInstaller

Hmm, I wouldn’t be surprised if this is just a convoluted permission error. I’ve checked the python36.dll inside the application you sent and the flag is definitely there so whatever the problem is, it’s not what it says it is. Looking back at the source code I notice that that flag is the first attribute/function to be loaded from said DLL so it’s quite likely that Py_DontWriteBytecodeFlag is a red-herring and the real problem is it’s not able to load the DLL at all. I do see a fail-safe for failing to load the DLL although I can’t verify if it works…

Ryan Ma

unread,
Dec 3, 2020, 4:22:41 AM12/3/20
to PyInstaller
Thanks for looking into this last month.

As suspected, the issue stemmed from problems loading the DLL. The user had a 3rd party application called AppSense that was blocking the dll from running. They had whitelisted the executable, but the unpacked components in the tempdir were still being blocked.

A realization from debugging this is that the error surfaced is different depending on how the DLL is blocked. When I tried blocked the python36.dll with Windows AppLocker or other Software Restriction Policies, I was getting the below error:
Error loading Python DLL %TEMP%\_MEIxxxxx\python36.dll
LoadLibrary: This program is blocked by group policy. For more information, contact your system administrator.

When blocked with AppSense, the following error was surfacing which is what I initially asked about.
Failed to get address for Py_DontWriteBytecodeFlag
GetProcAddress: The specified procedure could not be found.

Regards,

Ryan
Reply all
Reply to author
Forward
0 new messages