Python PyInstaller生成一个连续调用子进程的exe
我正试图编写一个简单的脚本,作为.exe执行。此脚本的目的是通过调用subprocess.check_call()来安装.whl文件,并安装.whl包,该包作为数据添加,并在pyinstaller中使用--add data标志。我对此有点过火(甚至尝试asyncio,认为在继续之前需要等待该过程)。 代码如下:Python PyInstaller生成一个连续调用子进程的exe,python,subprocess,pyinstaller,Python,Subprocess,Pyinstaller,我正试图编写一个简单的脚本,作为.exe执行。此脚本的目的是通过调用subprocess.check_call()来安装.whl文件,并安装.whl包,该包作为数据添加,并在pyinstaller中使用--add data标志。我对此有点过火(甚至尝试asyncio,认为在继续之前需要等待该过程)。 代码如下: #!/etc/python3.8 import sys as _sys import subprocess as _sub from pathlib import Path imp
#!/etc/python3.8
import sys as _sys
import subprocess as _sub
from pathlib import Path
import asyncio
MIN_PYTHON_VERSION = (3, 7, 1)
wheelfile = 'mywheel.whl'
def sys_check():
if _sys.version_info < MIN_PYTHON_VERSION:
raise EnvironmentError
async def pipMe(package):
return _sub.check_call([_sys.executable, '-m', 'pip', 'install', package])
async def main():
try:
if sys_check and Path(wheelfile):
print(f"Installing {wheelfile} to Python {_sys.version}.")
res = await asyncio.gather(pipMe(wheelfile))
return res
except EnvironmentError:
print(
f"Python {'.'.join(map(str, MIN_PYTHON_VERSION))} or greater is required to run this utility, "
f"but you have {_sys.version}! Please update Python.")
_sys.exit(1)
except KeyboardInterrupt:
print('Exiting')
_sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())
_sys.exit(1)
#/etc/蟒蛇3.8
将系统导入为_sys
将子流程导入为_sub
从pathlib导入路径
导入异步
MIN_PYTHON_版本=(3,7,1)
wheelfile='mywheel.whl'
def系统检查()
如果\u sys.version\u info
问题出在这里。当我尝试运行PyInstaller时,一切似乎都正常,但是运行可执行文件会继续循环子进程,并且不会完成控制盘的安装
用于在Windows Powershell中生成文件的Pyinstaller命令:
PS E:\PersonalProjects\wheel\u installer>pyinstaller.exe--添加数据'.\mywheel.whl;'--一个文件。\wheel\u installer.py
当我运行.\dist\wheel\u installer.exe时,我会在几秒钟内得到一个常量“Installing mywheel.whl to Python…”。如果我用asyncio运行它来尝试并等待子进程,那么在sub.check_调用例程中执行脚本就会失败
我不知所措,有人有什么想法吗?我想我刚刚意识到了这个问题,也许有人可以证实这一点,但是PyInstaller创建了自己的python实例以单独运行,这意味着运行whl的任何子进程都将安装在单独的实例上,而不是系统python上。我理解对了吗?