pyinstaller exe没有任何依赖关系? [英] pyinstaller exe without any dependencies?

查看:127
本文介绍了pyinstaller exe没有任何依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将pyinstaller与python27配合使用,只要与构建文件夹位于同一目录中,我的exe就可以很好地运行。我需要它是一个完全独立的exe,没有任何依赖关系,有没有办法将构建文件夹中的重要内容捆绑到一个文件中?

So I'm using pyinstaller with python27, and my exe works great so long as it's in the same directory as the build folder. I need it to be a completely standalone exe, without any dependencies, is there a way to bundle the important things from the build folder into one file? Neither -F nor --onefile seems to do this.

编辑:正如我在下面的回答中所述,我认为pyinstaller是问题所在,因为该exe仅在以下版本中运行dist文件夹,所以我认为它在那里有依赖关系,但实际上,它正在运行,然后由于仅在exe在桌面上时才触发的错误而立即崩溃。

as I explain in my answer below, I thought pyinstaller was the problem because the exe would only run in the dist folder, so I assumed it had dependencies there, but in reality, it was running and then instantly crashing due to a bug that only triggered when the exe was on the desktop.

推荐答案

我发现它不起作用的原因与pyinstaller或dll没有关系。该exe文件正在打开,并尝试通过python输入应有的powershell命令。不幸的是我有一行这样的代码:

I figured out that the reason it wasn't working had nothing to do with pyinstaller or dlls. The exe was opening, and and trying to input powershell commands via python like it was supposed to. Unfortunately I had a line of code that said this:

subprocess.check_output('schtasks /create /sc minute /mo ' + str(time) + ' /tn "test_process_to_run_every_'+str(time)+'_min" /tr //'+sys.argv[0],shell=True)
#set this exe to run every X minutes in windows scheduled tasks

问题是当我把exe放在sys.argv [0]时改变了在桌面上,最终成为一个看起来像C:// Users / John Smith / Desktop的路径。约翰和史密斯之间的空格使powershell疯狂并使程序崩溃,因此我使用以下代码行对其进行了转义:

the problem was that sys.argv[0] changed when I put the exe on the desktop, and ended up being a path that looked like C://Users/John Smith/Desktop. The space in between John and Smith made powershell mad and crashed the program, so I escaped it using this line of code:

path = sys.argv[0].replace(" ","^")

然后我替换了sys.argv [0]和我的新路径变量。希望这对将来尝试做相同事情的人有所帮助。

and then I replaced sys.argv[0] with my new path variable. Hope this helps anyone in the future trying to do the same thing.

这篇关于pyinstaller exe没有任何依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆