13

I have successfully edited my spec file and added the folder with my data to it. It builds fine but it still can't access the data. WHen i try to run the compiled .exe i get this error: Error loading Python DLL: C:\Users\Sal\AppData\Local\Temp\_MEI60122\python27.dll (error code 126)

EDIT 1 - I still don't have this figured out my spec file looks like this:

a = Analysis(['Clock_In.py'],
             pathex=['C:\\Users\\Sal\\Desktop'],
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)
a.datas += [('CO_time.pkl','CO_time.pkl', 'DATA')]
a.datas += [('hours.pkl','hours.pkl', 'DATA')]
a.datas += [('Obj_file.pkl','Obj_file.pkl', 'DATA')]
a.datas += [('weekly_hours_dict.pkl','weekly_hours_dict.pkl', 'DATA')]



pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.datas,
          a.binaries,       
          a.scripts,
          exclude_binaries=True,
          name='Clock_In.exe',
          debug=False,
          strip=None,
          upx=True,
          console=True, 
          icon="C:\Users\Sal\Desktop\Raindropmemory-Legendora-BrokenSword.ico")
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               **name='Clock_In')

EDIT 2

I am using 32-Bit python on a 64-bit OS(windows 8) and it has been brought to my attention that this could potentially be causing my issue, but still no solution.

EDIT 3

So i have just tried download 64-bit python and putting it in my system path. ran pyinstaller with my .spec file and still got the exact same error code! What is going on here! A curious detail though is that the icon="C:\Users\Sal\Desktop\Raindropmemory-Legendora-BrokenSword.ico") statement from spec file executed and updated the icon successfully, where as before it would not.

EDIT 4

This is the statement i have in my code for MEIPASS straight from the documentation.

if getattr(sys, 'frozen', False):
# we are running in a |PyInstaller| bundle
basedir = sys._MEIPASS
else:
# we are running in a normal Python environment
basedir = os.path.dirname(__file__)
After_Sunset
  • 674
  • 3
  • 10
  • 25

5 Answers5

9

I found same error after creating a standalone executable like this:

pyi-makespec.exe -F program.py
## Customize script.spec just created

and

pyinstaller.exe -F script.spec

so I needed to run the executable as administrator to solve it.

I don't know the reason because it wasn't my computer. I had done the process in mine first and worked like a charm but not there. Perhaps some security configuration or a weird installation of or , but I add this solution here because I was looking for hours without success, and it's a simple task that can save you some time before trying more complex approaches.

Birei
  • 35,723
  • 2
  • 77
  • 82
4

You put that code snippet right at the top of the Python script you are turning into an executable - not in the spec and not in its own script. I found an example here:

https://shanetully.com/2013/08/cross-platform-deployment-of-python-applications-with-pyinstaller/

bmshort
  • 208
  • 1
  • 6
  • Thanks i can't tell if it helped or not but after adding i am now getting this `Error loading Python DLL: C:\Users\Sal\AppData\Local\Temp\_MEI60122\python27.dll (error code 126)` any clue about this? – After_Sunset Aug 08 '14 at 02:17
  • What options are you giving to your call to pyinstaller? I believe you will need -F at a minimum - see http://stackoverflow.com/questions/19225132/pyinstaller-not-working-on-simple-helloworld-program -- but double-check the manual to see if you require other flags as well - http://pythonhosted.org/PyInstaller/#using-pyinstaller – bmshort Aug 08 '14 at 02:27
  • I tried that it didn't do anything. I am using this: `pyinstaller Clock_In.spec` but still getting that same error code `Error loading Python DLL: C:\Users\Sal\AppData\Local\Temp\_MEI60122\python27.dll (error code 126)` – After_Sunset Aug 08 '14 at 02:43
  • Just to be clear it compiles fine and all the necessary data files are there its when i try to click the .exe i get this. – After_Sunset Aug 08 '14 at 02:44
  • 1
    Do you have Python in your path? Seems like it is having trouble locating it. I have also seen this when I had a 32-bit Python distro on a 64-bit os and it found python27.dll but for the wrong platform. – bmshort Aug 08 '14 at 02:53
  • Yes , im in the same boat. I have python 32-bit on a 64-bit OS(Windows 8). I checked my path and python is there. SO how did you resolve it? Any suggestions? I really need to get to the bottom of this lol. – After_Sunset Aug 08 '14 at 03:30
  • So after changing my system path to 64-bit python and re-compiling i still get that exact same error code 126! A curious detail though this time it actually executed the `icon="C:\Users\Sal\Desktop\Raindropmemory-Legendora-BrokenSword.ico")` successfully from my spec file and updated the icon where-as before it wouldn't – After_Sunset Aug 09 '14 at 22:51
  • Interesting. Are there any other Python libraries you are using aside from Pyinstaller? If so did you reinstall them after you put down the new Python? – bmshort Aug 10 '14 at 22:27
1

Having the same issue on python3.7 on windows 10.

Fixed this by adding --upx-exclude"vcruntime140.dll" option.

More info can be found here

double
  • 11
  • 1
  • How does that fix the problem? Dont' just blurt out code. Explain yourself! https://stackoverflow.com/help/how-to-answer – Rob Jul 26 '19 at 10:09
  • I found in [this post](https://github.com/spesmilo/electrum/pull/3185) mentioning Pyinstaller requires Visual C++ 2015, but I had 2017 version installed. There might be some issue with my VC++ file, this option is telling pyinstaller to skip the broken file while packing. Please follow the info I gave in the post if you're interested about the UPX packing. – double Jul 29 '19 at 02:12
  • works for me, thanks. Got similar error for python 3.6 – suit Jan 22 '20 at 06:13
0

I encountered the same issue, and finally find the reason is anti-virus software treat "python27.dll" as a trojan, and deleted it when exe try to load.

The problem is solved by add "...\AppData\Local\Temp\" to trusted zone.

peicj
  • 1
0

One simple thing to do is to delete all the stuff in the following folder: C:\Users\xxx\AppData\Roaming\pyinstaller. I've fixed the issue after I cleaned this folder. Maybe also delete all the files which are created by Pyinstaller last time.

m_fft
  • 11