简体   繁体   English

使用 pyinstaller 创建 python windows 可执行文件时出现问题 - 创建、运行但立即退出

[英]Problem creating a python windows executable with pyinstaller - creates, runs but quits immediately

I have the sample python code below.我有下面的示例python代码。 I create a windows executable app using PYINSTALLER.我使用 PYINSTALLER 创建了一个 Windows 可执行应用程序。 When it runs, it immediately quits.当它运行时,它立即退出。 What should I be doing?我该怎么办?

I also tried a basic (default) flask app - I get the same effect.我还尝试了一个基本的(默认)flask 应用程序 - 我得到了同样的效果。 I don't see any errors - just the window opens and closes immediately.我没有看到任何错误 - 只是窗口立即打开和关闭。 I have searched all over for solutions - the stackoverflow ar Python script executable crashes immediately does not help.我四处寻找解决方案 - stackoverflow ar Python 脚本可执行文件立即崩溃并没有帮助。 I am sure smart people have already solved this.我相信聪明的人已经解决了这个问题。 Please help请帮忙

import sys
import zerorpc


class Api(object):
    def echo(self, text):
        """echo any text"""
        return text


def main():
    addr = 'tcp://127.0.0.1:4242'
    s = zerorpc.Server(Api())
    s.bind(addr)
    print('start running on {}'.format(addr))
    s.run()


if __name__ == '__main__':
    main()

So, in my case - when I installed python (3.7.x), pyinstaller was installed with it.所以,就我而言 - 当我安装 python (3.7.x) 时,pyinstaller 也安装了。 I assumed I could use this(now I know better).我以为我可以使用它(现在我知道得更好了)。 I did not install a separate pyinstaller in my virtual env - but I was using that to build the exe.我没有在我的虚拟环境中安装单独的 pyinstaller - 但我使用它来构建 exe。 This was the source of my problem - bcos, as soon as I did a pip install pyinstaller into my v.env - it worked!!!这是我的问题的根源-bcos,只要我将 pip install pyinstaller 安装到我的 v.env 中-它就起作用了!!! I am sure it is obvious to many of you who have been at python for a long time - not so for newcomers我相信对于很多在 Python 工作了很长时间的人来说这是显而易见的——对于新手来说并非如此

I hope I help somebody who may run into this similar problem.我希望我能帮助可能遇到类似问题的人。 We continue to learn我们继续学习

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM