【问题标题】:How to use pyinstaller in subprocess windows?如何在子进程窗口中使用 pyinstaller?
【发布时间】:2016-03-07 18:42:25
【问题描述】:

它在 cmd.exe 控制台中对我有用:

C:\tools\python2-x86_32\Scripts\pyinstaller.exe --name="Name app" --onefile --windowed --icon=tk.ico script.py

但是我需要编译python

这不起作用:

subprocess.call(['C:\tools\python2-x86_32\Scripts\pyinstaller.exe ','--name','Name app','--onefile ','--windowed','--icon=','tk.ico','script.py'])
Traceback (most recent call last):
  File "C:/Users/usercom/Documents/sql_alpha/sqlms.py", line 96, in <module>
    subprocess.call(['C:\tools\python2-x86_32\Scripts\pyinstaller.exe

','--name','分析日志 Pre-Alpha 1','--onefile ','--windowed','--icon=','tk.ico','tk.py']) 文件“C:\tools\python2-x86_32\lib\subprocess.py”,第 522 行,调用中 返回 Popen(*popenargs, **kwargs).wait() init 中的文件“C:\tools\python2-x86_32\lib\subprocess.py”,第 710 行 读错,写错) _execute_child 中的文件“C:\tools\python2-x86_32\lib\subprocess.py”,第 958 行 启动信息) Windows 错误:[错误 2]

这不起作用:

cmd = 'C:\tools\python2-x86_32\Scripts\pyinstaller.exe --name="Name app" --onefile --windowed --icon=tk.ico script.py'
subprocess.Popen(cmd, stdout=subprocess.PIPE)
> Traceback (most recent call last):
  File "C:/Users/usercom/Documents/sql_alpha/sqlms.py", line 97, in <module>
    subprocess.Popen(cmd, stdout=subprocess.PIPE)
  File "C:\tools\python2-x86_32\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\tools\python2-x86_32\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 5] 

如何让它发挥作用?

【问题讨论】:

  • 你可以尝试用'"Name app"'替换'Name app'
  • 错误 5 对应于拒绝访问。那么您可以尝试以管理员身份运行您的 python 脚本吗?
  • 它不会改变任何东西('Name app' 和 '"Name app"' 。
  • 我以管理员身份在 cmd.exe 中运行我的脚本。它不会改变任何东西
  • 使用原始字符串:cmd = r'C:\tools\python2-x86_32\Scripts\pyinstaller.exe --name="Name app" --onefile --windowed --icon=tk.ico script.py'。如果您不使用原始字符串,则字符串文字 '\t' 是一个制表符。

标签: python windows python-2.7 subprocess pyinstaller


【解决方案1】:

有效:

subprocess.call([r'C:\tools\python2-x86_32\Scripts\pyinstaller.exe','--name','Name app', '--onefile','--windowed','tk.py'])

感谢塔伦·贝哈尔! 谢谢 eryksun!

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多