Python pyinstaller在创建exe后加载文件
我运行的是2.7,我使用的是pyinstaller。我的目标是输出一个exe,并让它运行我的另一个类文件。我还将其用作语音识别的框架。我已经在dragonfly->examples->text.py下的examples方向创建了另一个文件。如果我用我的IDE运行,我可以说语音命令,它会理解我创建的以下文件和蜻蜓示例中的其他示例文件Python pyinstaller在创建exe后加载文件,python,pyinstaller,Python,Pyinstaller,我运行的是2.7,我使用的是pyinstaller。我的目标是输出一个exe,并让它运行我的另一个类文件。我还将其用作语音识别的框架。我已经在dragonfly->examples->text.py下的examples方向创建了另一个文件。如果我用我的IDE运行,我可以说语音命令,它会理解我创建的以下文件和蜻蜓示例中的其他示例文件 from dragonfly.all import Grammar, CompoundRule, Text, Dictation import sys sys
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"
如果我明白的话。您有您的脚本和一些示例脚本,它们调用您的脚本来显示它正在工作 你没有抓住要点。 您的脚本应该是最终产品 如果您想测试功能,请在开发版本中进行测试。 如果要测试exe文件,请使用另一个单独的测试脚本 其他事项: 脚本和模块是完全不同的东西。 您正在尝试将脚本作为模块导入,并在示例脚本中使用它 如果需要,我建议您使用参数构建脚本的主要入口点,因为这是注定要完成的。 并制作其他运行脚本的示例脚本 或者制作一个模块并生成使用该模块的脚本。 然后将此示例脚本构建到exe文件,该文件使用该模块并显示其工作原理
PyInstaller可以一次编译一个脚本。不需要强迫它做不寻常的事情。我的主脚本dragonfly-main.py正在将目录中的每个示例文件作为模块加载。它可以在IDE中很好地实现这一点,但在使用pyinstaller时,无论出于何种原因,它都无法获取我的示例文件。dragonfly main不知道其他模块是什么。示例文件是示例文件而不是模块。创建单独的项目,将蜻蜓导入其中。如果你需要示例文件中的代码-复制并通过它到你的项目中,你需要多少。你是对的,我正在尝试向后做所有事情哈哈。我是python新手。谢谢你的帮助。