简体   繁体   English

exe创建后,Python Pyinstaller加载文件

[英]Python pyinstaller loading files after exe creation

I am running 2.7 and i am using pyinstaller. 我正在运行2.7,正在使用pyinstaller。 My goal is to output a exe and also have it run my other class file. 我的目标是输出一个exe,并让它运行我的其他类文件。 I am also using https://code.google.com/p/dragonfly/ as a framework for voice recognition. 我还将https://code.google.com/p/dragonfly/用作语音识别框架。 I have created another file in the examples direction under dragonfly->examples->text.py . 我已经在dragonfly-> examples-> text.py下的示例方向上创建了另一个文件。 If i run https://code.google.com/p/dragonfly/source/browse/trunk/dragonfly/examples/dragonfly-main.py?spec=svn79&r=79 with my IDE i can say voice commands and it will understand the below file i have created and the other example files that are in the dragonfly examples. 如果我在我的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.

I noticed in console that it will output 我在控制台中注意到它将输出

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

After i have used pyinstaller the output for that line is 在我使用pyinstaller之后,该行的输出是

UNKNOWN: valid paths: []

So its not loading the examples because it cannot find them. 因此,由于找不到示例,因此未加载示例。 How can i tell pyinstaller to also load the example files when it is creating an exe? 我如何告诉pyinstaller在创建exe时也加载示例文件? And If it does load the files how can i make sure my exe knows where the files are? 并且,如果确实加载了文件,我如何确保我的exe知道文件在哪里?

The command i am running for pyinstaller 我正在为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"

If I understand clearly. 如果我明白了。 You have your script and some examples scripts which call your script to show that it is working? 您有自己的脚本以及一些示例脚本,这些脚本调用您的脚本以表明其正常工作?

You are missing the point. 您错过了重点。 Your script supposes to be an end product. 您的脚本应该是最终产品。

If you want to test functionality do it in development version. 如果要测试功能,请在开发版本中进行。
If you want to test exe file do it by another(separated) test script. 如果您要测试exe文件,请使用另一个(单独的)测试脚本进行测试。

Other thing: 另一件事:
Scripts and modules are totally different things. 脚本和模块是完全不同的东西。
You are trying to import your script as module and use it in example script. 您正在尝试将脚本导入为模块,并在示例脚本中使用它。

I suggest you to build main entry point to script (with parameters if you need) as it is meant to be done. 我建议您按需构建脚本的主要入口点 (如果需要,可以使用参数)。 And make other example script which run your script. 并制作其他示例脚本来运行您的脚本。

Or make a module and build script which uses this module. 或制作一个模块并使用该模块构建脚本。 Then build this example script to exe file which uses that module and shows it works 然后将该示例脚本构建为使用该模块的exe文件,并显示其工作原理

PyInstaller can compile one script at once. PyInstaller可以一次编译一个脚本。 Forcing it to do unusual things is not needed. 不需要强迫它执行不寻常的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pyinstaller 创建 exe 后在 Windows 7 上加载 python37 dll 时出错 - Error loading python37 dll on Windows 7 after Pyinstaller created exe Pyinstaller EXE 文件不是独立的? - Pyinstaller EXE Files are not independent? 使用pyinstaller制作.exe文件后可以删除哪些文件? - What files can I delete after making .exe file with pyinstaller? 如何使用pyinstaller将多个python文件编译成单个.exe文件 - How to compile multiple python files into single .exe file using pyinstaller 使用pyinstaller使其执行后,python脚本不起作用 - python script not working after using pyinstaller to make it .exe 使用 pyinstaller 将其转换为 exe 后,带有单例的 python 脚本不起作用 - python script with singleton doesn't work after converting it to exe with pyinstaller python 脚本在使用 pyinstaller 转换为 exe 后重复第一个命令 - python script repeats first command after converted to exe with pyinstaller PyInstaller 更新到 Python 后不生成 exe 10 - PyInstaller does not make the exe after updating to Python 10 Python 使用 pyinstaller 创建 EXE 后将图像转换为视频的脚本出现问题 - Problem with Python Script that converts images to video after creating EXE with pyinstaller 使用pyinstaller创建后无法运行python exe文件 - Cannot run python exe file after create with pyinstaller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM