为pyinstaller加载python27.dll错误时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25194463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error loading python27.dll error for pyinstaller
提问by After_Sunset
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)
我已成功编辑我的规范文件并将包含我的数据的文件夹添加到其中。它构建良好,但仍然无法访问数据。当我尝试运行已编译的 .exe 时,出现此错误: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:
编辑 1 -我仍然没有弄清楚我的规范文件是这样的:
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
编辑 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.
我在 64 位操作系统(windows 8)上使用 32 位 python,我注意到这可能会导致我的问题,但仍然没有解决方案。
EDIT 3
编辑 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.
所以我刚刚尝试下载 64 位 python 并将其放在我的系统路径中。使用我的 .spec 文件运行 pyinstaller 并且仍然得到完全相同的错误代码!这里发生了什么!不过,一个奇怪的细节是,icon="C:\Users\Sal\Desktop\Raindropmemory-Legendora-BrokenSword.ico")spec 文件中的语句成功执行并更新了图标,而以前则不会。
EDIT 4
编辑 4
This is the statement i have in my code for MEIPASS straight from the documentation.
这是我在 MEIPASS 代码中直接从文档中得到的声明。
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__)
采纳答案by bmshort
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:
您将该代码片段放在要转换为可执行文件的 Python 脚本的顶部 - 不在规范中,也不在其自己的脚本中。我在这里找到了一个例子:
https://shanetully.com/2013/08/cross-platform-deployment-of-python-applications-with-pyinstaller/
https://shanetully.com/2013/08/cross-platform-deployment-of-python-applications-with-pyinstaller/
回答by Birei
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 pythonor wxpython, 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.
我不知道原因,因为它不是我的电脑。我首先在我的过程中完成了这个过程,并且像魅力一样工作,但不在那里。也许是一些安全配置或python或wxpython的奇怪安装,但我在这里添加这个解决方案是因为我一直在寻找几个小时但没有成功,这是一项简单的任务,可以在尝试更复杂的方法之前为您节省一些时间。
回答by peicj
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.
我也遇到了同样的问题,最后找到原因是杀毒软件把“python27.dll”当作木马,在exe尝试加载时删除了。
The problem is solved by add "...\AppData\Local\Temp\" to trusted zone.
该问题通过将“...\AppData\Local\Temp\”添加到受信任区域来解决。
回答by m_fft
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.
一件简单的事情是删除以下文件夹中的所有内容:C:\Users\xxx\AppData\Roaming\pyinstaller。清理此文件夹后,我已解决此问题。也可以删除上次 Pyinstaller 创建的所有文件。

