我想从pyinstaller编译的python文件中执行一个exe文件
我正在使用以下代码:
import subprocess, os, sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
new_path = resource_path("executable.exe")
print new_path
subprocess.Popen(new_path)
我用的是:
^{pr2}$威奇创造了incluse.exe文件如果我执行它,我会得到以下错误:
C:\Users\MyUsername\AppData\Local\Temp\_MEI13~1\executable.exe
Traceback (most recent call last):
File "incluse.py", line 16, in <module>
File "subprocess.py", line 394, in __init__
File "subprocess.py", line 644, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified
[21812] Failed to execute script incluse
我要它做的是执行可执行文件.exe我包括在内,威奇应该会给你一个留言框
您可以使用pyinstaller使用
add-binary
选项将另一个二进制文件捆绑到exe中。在在Python脚本中,可以使用
subprocess.Popen(exe_path)
调用嵌入在exe中的exe。您可以使用sys._MEIPASS
访问exe所在的临时位置,以便生成指向exe的路径。在示例
油灰_启动器.py
文件夹结构
^{pr2}$在根文件夹中,执行:
pyinstaller add-binary "binaries\putty.exe;binaries" onefile putty_launcher.py
然后,这将从putty生成一个exe_启动器.py可以成功调用版本的脚本腻子.exe嵌入exe中。在
相关问题 更多 >
编程相关推荐