【问题标题】:How to run 'pythondialog' codes under Windows?如何在 Windows 下运行“pythondialog”代码?
【发布时间】:2019-03-16 02:51:28
【问题描述】:

我最近在学习pythondialog。我尝试从这里运行示例代码:http://pythondialog.sourceforge.net/#installation

这是代码:

#! /usr/bin/env python3

import locale
from dialog import Dialog

locale.setlocale(locale.LC_ALL, '')
d = Dialog(dialog="dialog")
d.set_background_title("My little program")
if d.yesno("Are you REALLY sure you want to see this?") == d.OK:
    d.msgbox("You have been warned...")
    code, tags = d.checklist("What sandwich toppings do you like?",
                         choices=[("Catsup", "",             False),
                                  ("Mustard", "",            False),
                                  ("Pesto", "",              False),
                                  ("Mayonnaise", "",         True),
                                  ("Horse radish","",        True),
                                  ("Sun-dried tomatoes", "", True)],
                         title="Do you prefer ham or spam?",
                         backtitle="And now, for something "
                         "completely different...")
    if code == d.OK:
        pass
else:
    code, tag = d.menu("OK, then you have two options:",
                   choices=[("(1)", "Leave this fascinating example"),
                            ("(2)", "Leave this fascinating example")])
    if code == d.OK:
        pass

它可以在linux--debian下工作,当我使用“apt install python3-dialog”时。如果我只pip install 'pythondialog',程序错误:'ExecutableNotFound...'

现在我正在尝试使用pycharm在windows10下运行代码,但出现同样的错误:

...  
File "D:\PycharmProjects\test\venv\lib\site-packages\dialog.py", line 469, in _path_to_executable
"can't find the executable for the dialog-like "
dialog.ExecutableNotFound: Executable not found: can't find the executable for the dialog-like program

我想我似乎安装了关于 dialog() 的“exe”,但我不知道该怎么做。 我在网上找了很久。但是没有用。请帮助或尝试提供一些想法如何实现这一目标。

提前致谢。

【问题讨论】:

  • 请将代码放入pastebin而不是显示在图片中。

标签: python dialog


【解决方案1】:

错误信息非常清楚:“找不到可执行文件:找不到类似对话框的程序的可执行文件”。 pythondialog 通过调用dialog 程序来工作。然而,被调用程序的名称并不重要,重要的是它表现得像对话框;因此,任何与对话框兼容的程序都可以。在 pythondialog 文档(manual 和其他页面或文件)中,接受与对话框相同的命令行参数并在给定相同的命令行参数时行为相似的程序称为 dialog-like program )。

所以,pythondialog 需要一个我们刚刚定义的类似对话框的程序。默认情况下,它使用PATH 环境变量在名称dialog 下查找此程序,但如果您愿意,可以显式选择特定名称或可执行文件的完整路径。例如,如果您有一个名为 foobar 的类似对话框的程序,该程序存在于您的 PATH 的目录之一中,则使用 Dialog(dialog="foobar") 构造 Dialog 实例将使所有小部件使用以下方法显示该对象将使用foobar 而不是dialog 作为底层引擎。

在 Debian 上使用 apt install python3-dialog 时没有出现错误的原因是 python3-dialog Debian 软件包依赖于 dialog Debian 软件包。因此,您在PATH 的一个目录中以默认名称dialog 安装了一个类似对话框的程序(通常在/usr/bin 中,除非您有一个名为dialog 的else在您的 PATH 中更早的位置,例如 dialog 的本地安装。

但是,当您尝试在 Windows 上使用 pythondialog 时,您没有满足安装类似对话框的程序的基本要求,这就是您收到“找不到可执行文件”错误的原因。 PyPI page for pythondialog 表示“操作系统:Unix”,因为 dialog 需要 Unix(或 POSIX)终端才能运行,AFAIK。因此,pythondialog 不能在 Windows 上本地运行也就不足为奇了。但是,它很可能在 Windows 下在 Cygwin 中工作。实际上,对话框似乎已移植到 Cygwin。当然,您需要安装此端口,并且至少在 Cygwin 终端中运行您的程序(在这种情况下,我不确定 Python 安装是否也必须是 Cygwin 端口,因此您可能想尝试使用本机Windows 下的 Python,但请务必从 Cygwin 提供的终端运行程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 1970-01-01
    相关资源
    最近更新 更多