简体   繁体   English

如何将Python项目转换为可执行文件

[英]How to convert Python project into executable

I have a Python project that I want to convert into an executable. 我有一个要转换为可执行文件的Python项目。 I have installed Pyinstaller. 我已经安装了Pyinstaller。 I only know how to convert one single script into .exe, but I have multiple packages with multiple python scripts. 我只知道如何将一个脚本转换为.exe,但是我有多个包含多个python脚本的软件包。

The command line I used with success is: 我成功使用的命令行是:

pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py

pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. pyinstaller可以很好地管理您导入的多个“ .py”文件,无需引用它们。 Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main. 在“添加数据”选项下,您列出了非py文件,在我的示例中,“ cprofiles_lmfit.py”文件是包含主文件的文件。

But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. 但是如此处所示, 需要帮助来使用pyinstaller编译python (以及其他几篇文章),我是pyinstaller的初学者。 I was never able to use the 'theano' module and I did not optimize. 我从来没有使用过'theano'模块,也没有进行优化。 I still have to test the suggestions in the answer. 我仍然必须测试答案中的建议。

1) Open the command prompt 1)打开命令提示符

2) Install pyinstaller Pip install pyinstaller 2)安装pyinstaller Pip安装pyinstaller

3) Test your python script first just to check python script should work with normal .py extension. 3)首先测试您的python脚本,只是要检查python脚本是否可以正常使用.py扩展名。 Saurabh is the name of python file python saurabh.py Saurabh是python文件的名称python saurabh.py

4) Convert the python into executable file pyinstaller --onefile Saurabh.py 4)将python转换为可执行文件pyinstaller --onefile Saurabh.py

Notice we have passed “–onefile” as a argument which tell pyinstaller to create only one file 注意,我们已经传递了“ –onefile”作为参数,告诉pyinstaller仅创建一个文件

5) Go to directory and navigate to the dist folder. 5)转到目录并导航到dist文件夹。

Prerequisite : Install PyQt5 to avoid error. 先决条件:安装PyQt5以避免错误。 pip install PyQt5 点安装PyQt5

将主脚本转换为.exe应该可以解决该问题,请使用-onefile将其转换为一个exe,其余的.py文件应包括在内。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM