首页 > 解决方案 > 是否可以将构建的 pyinstaller 可执行文件导入 python 脚本?

问题描述

是否可以在 python 脚本中导入构建的 pyinstaller 包?

例如,我在以下脚本上运行了 pyinstaller:

count_to_ten.py

def count():
   for i in range(10):
      print(i)

然后,我将其与 pyinstaller 打包,pyinstaller -F count_to_ten.py用于生成可执行文件count_to_ten.exe

我知道我可以count_to_ten.py使用导入import count_to_ten,然后count()根据需要调用。

exec除了使用or执行此操作之外,是否有任何等效的方法可以使用“内置”pyinstaller 文件执行此操作subprocess

理想情况下相当于:

main.py

import count_to_ten.exe

count_to_ten.count()

编辑 建议解决方案“在使用 PyInstaller 创建的单文件 exe 中导入外部模块”解决了这个问题。建议的解决方案解决了相反的问题。

上述解决方案涉及将外部.py文件导入 pyinstaller 创建的单文件 exe。我想在不使用or的情况下将单文件 exe 文件导入解释.py脚本。execsubprocess

标签: pythonpython-importpyinstaller

解决方案


推荐阅读