pyinstaller / pyinstaller

Freeze (package) Python programs into stand-alone executables
http://www.pyinstaller.org
Other
11.8k stars 1.94k forks source link

Access violation when running .exe in Windows (Data Execution Prevention) #3576

Closed zamora18 closed 6 years ago

zamora18 commented 6 years ago

Hello,

I have created a GUI (using PyQt4) that uses a 3rd party library pylink. This library allows me to flash firmware onto an STM micro-controller using a J-Link Programmer connected through USB to my computer. The program works great when developing in my IDE (PyCharm), but after bundling the GUI in an executable (using pyinstaller) I get this error (with varying locations 0x00____ ):

WindowsError: exception: access violation writing 0x000000CE00000000

This is the full error output:

Traceback (most recent call last):
  File "main_gui.py", line 87, in run
  File "main_gui.py", line 57, in _flash_binary
  File "build\bdist.win-amd64\egg\pylink\jlink.py", line 172, in wrapper
  File "build\bdist.win-amd64\egg\pylink\jlink.py", line 2021, in flash_file
WindowsError: exception: access violation writing 0x000000CE00000000

I have no problem accessing the 3rd party library, so I am fairly confident that I packaged the executable correctly and that the dll was loaded successfully.

After having done some research I believe that the problem is that it is being denied access to memory because the bundled .exe has DEP (Data Execution Prevention) protection. (See this article).

I searched the pyinstaller FAQ and email list but did not find anything that helped me in regards to disabling DEP from pyinstaller. I also attempted to turn off DEP in Windows for my specific application, but I cannot set DEP on 64-bit executables.

I have done a fair amount of testing and review, and when debugging I do not receive any relevant debug messages in the console when the code is executed.

More information on my setup:

Thank you for your help.

wxd9199 commented 6 years ago

i have the same problem..... at last..... when is happened i execute 'os.system("start cmd /c JLinkSTM32.exe -SetDeviceFamily 2")' i know this is not a good way to connect the device...

htgoebel commented 6 years ago

For me this looks like an implementation issue in the JLink-Programmer interface. There should be no need to execute data for communicating via USB-port. Esp. the example @wxd9199 posted shows that this is caused by JLink.

I can not tell you why it works in PyCharm but not hen bundled. But I can not see how this is releated to PyInstaller. Thus I'm closing this.

zamora18 commented 6 years ago

@wxd9199 I have tried your "fix" but it is still not working for me. What determines the SetDeviceFamily parameter? I am using a J-Link Plus programmer. Are you executing this after the exception is caught? It works in a bundled GUI?

wl496928838 commented 6 years ago

How do I solve it?

There seems to be no problem in using py2exe.