【问题标题】:accessing python interpreter from a pyinstaller bundle #2从 pyinstaller bundle #2 访问 python 解释器
【发布时间】:2020-02-16 22:58:28
【问题描述】:

我正在尝试执行包含在数据中的 python 脚本,并捆绑到 pyinstaller 可执行文件中(在 Mac 上)。我需要将参数传递给这个脚本,所以我不能只执行(open(read())。在pyinstaller之外,sys.executable是python解释器,所以调用python脚本可以正常工作。在pyinstaller中,sys.executable是'主要'py脚本,所以它只是再次打开我的应用程序而不是调用新脚本。如何在我的应用程序中调用我的附加python脚本?这就是我想要实现的,它不适用于一个捆绑的 pyinstaller 应用程序:

subprocess.call([sys.executable, os.path.join(wd,"tests","errorMessage.py"), vArgument])

【问题讨论】:

    标签: python subprocess pyinstaller sys


    【解决方案1】:

    这就是我让它工作的方式,这有点笨拙。它没有像我最初想要的那样调用 python 解释器,而是执行包含参数的 py 脚本:

    # set the arguments beforehand
    sys.argv = [os.path.join(wd,"tests","errorMessage.py"), vArguments]
    # execute the script, but also bring in globals so imported modules are there
    exec(open(os.path.join(wd,"tests","errorMessage.py")).read(), globals())
    

    Pyinstaller 似乎在整个交易之后都可以工作了.. omg...

    【讨论】:

    • 您能否再解释一下您的答案。我想使用 pyinstaller python myscript.py install 运行这个命令。我可以做到这一点exec(open('opc_client_service.pyc').read()),但我无法理解如何将install 传递给它。
    猜你喜欢
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 2014-01-14
    • 1970-01-01
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多