【问题标题】:Python pyinstaller loading files after exe creationPython pyinstaller 在创建 exe 后加载文件
【发布时间】:2013-03-22 18:43:04
【问题描述】:

我正在运行 2.7,并且正在使用 pyinstaller。我的目标是输出一个 exe 并让它运行我的其他类文件。我还使用https://code.google.com/p/dragonfly/ 作为语音识别框架。我在 Dragonfly->examples->text.py 下的示例方向创建了另一个文件。如果我用我的 IDE 运行https://code.google.com/p/dragonfly/source/browse/trunk/dragonfly/examples/dragonfly-main.py?spec=svn79&r=79,我可以说出语音命令,它会理解我创建的以下文件以及蜻蜓示例中的其他示例文件。

    from dragonfly.all import Grammar, CompoundRule, Text, Dictation
import sys
sys.path.append('action.py')
import action

# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    print "This works"
    spec = "do something computer"                  # Spoken form of command.
    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print "Voice command spoken."

class AnotherRule(CompoundRule):
    spec = "Hi there"                  # Spoken form of command.
    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print "Well, hello"




# Create a grammar which contains and loads the command rule.
grammar = Grammar("example grammar")                # Create a grammar to contain the command rule.
grammar.add_rule(ExampleRule())                     # Add the command rule to the grammar.
grammar.add_rule(AnotherRule())                     # Add the command rule to the grammar.
grammar.load()           

                       # Load the grammar.

我在控制台中注意到它会输出

UNKNOWN: valid paths: ['C:\\Users\\user\\workspace\\dragonfly\\dragonfly-0.6.5\\dragonfly\\examples\\action.py',etc..etc...

在我使用 pyinstaller 之后,该行的输出是

UNKNOWN: valid paths: []

所以它没有加载示例,因为它找不到它们。我如何告诉 pyinstaller 在创建 exe 时也加载示例文件?如果它确实加载了文件,我如何确保我的 exe 知道文件在哪里?

我为 pyinstaller 运行的命令

C:\Python27\pyinstaller-2.0>python pyinstaller.py -p-paths="C:\Users\user\worksp
ace\dragonfly\dragonfly-0.6.5\dragonfly\examples\test.py" "C:\Users\user\workspa
ce\dragonfly\dragonfly-0.6.5\dragonfly\examples\dragonfly-main.py"

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    如果我理解清楚的话。你有你的脚本和一些示例脚本,它们调用你的脚本来表明它正在工作?

    你没有抓住重点。 您的脚本应该是最终产品。

    如果您想测试功能,请在开发版本中进行。
    如果您想测试 exe 文件,请使用另一个(单独的)测试脚本。

    其他:
    脚本和模块是完全不同的东西。
    您正在尝试将脚本作为模块导入并在示例脚本中使用。

    我建议您将主要的入口点构建到脚本中(如果需要,可以使用参数),因为它应该完成。 并制作其他示例脚本来运行您的脚本。

    或者制作一个模块并构建使用这个模块的脚本。 然后将此示例脚本构建为使用该模块并显示其有效的 exe 文件

    PyInstaller 可以一次编译一个脚本。不需要强迫它做不寻常的事情。

    【讨论】:

    • 我的主脚本 Dragonfly-main.py 将目录中的每个示例文件作为模块加载。它可以在 IDE 中很好地做到这一点,但是在使用 pyinstaller 时,无论出于何种原因,它都无法获取我的示例文件。 S Dragonfly-main 不知道其他模块是什么。
    • 示例文件是示例文件而不是模块。创建你的分离项目,将蜻蜓导入它。如果您需要示例文件中的代码 - 将其复制并粘贴到您的项目中,您需要多少。
    • 你是对的,我试图把所有的事情都倒过来哈哈。我是 python 新手。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 2019-07-18
    • 2021-02-11
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    相关资源
    最近更新 更多