Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Python编译到windows应用程序中_Python_Windows_Exe_Kivy - Fatal编程技术网

将Python编译到windows应用程序中

将Python编译到windows应用程序中,python,windows,exe,kivy,Python,Windows,Exe,Kivy,目前我正在从事其他人项目的一个分支,该项目是用Python编程语言编写的 我可以访问我需要的所有源代码,以及我想做的所有更改,并根据需要“设置”所有内容 我当前的步骤是尝试以某种方式编译它,因此它在独立应用程序中作为windows运行。我知道这是可能的,因为源应用程序就是这样运行的。目前,我可以使用python扩展模块WinPython、构建GUI的kivy框架本身等访问VisualStudio 但我似乎不知道该怎么做。我粗略的研究提出了一个名为py2exe的程序,但根据我的判断,该程序无法满足

目前我正在从事其他人项目的一个分支,该项目是用Python编程语言编写的

我可以访问我需要的所有源代码,以及我想做的所有更改,并根据需要“设置”所有内容

我当前的步骤是尝试以某种方式编译它,因此它在独立应用程序中作为windows运行。我知道这是可能的,因为源应用程序就是这样运行的。目前,我可以使用python扩展模块WinPython、构建GUI的kivy框架本身等访问VisualStudio

但我似乎不知道该怎么做。我粗略的研究提出了一个名为py2exe的程序,但根据我的判断,该程序无法满足我的需要。

创建等级库文件

对于本例,我们将打包touchtracer示例并嵌入一个自定义图标。touchtracer示例是kivy\examples\demo\touchtracer目录,主文件名为main.py

双击Kivy.bat,将打开一个控制台

转到pyinstaller 2.1目录并创建初始规范:

cd pyinstaller-2.1
python pyinstaller.py --name touchtracer ..\kivy\examples\demo\touchtracer\main.py
还可以将icon.ico文件添加到应用程序文件夹,以便为可执行文件创建图标。如果没有.ico文件,可以使用web应用程序ConvertICO将icon.png文件转换为ico。将icon.ico保存在touchtracer目录中,然后键入:

python pyinstaller.py --name touchtracer --icon ..\kivy\examples\demo\touchtracer\icon.ico ..\kivy\examples\demo\touchtracer\main.py
有关更多选项,请参阅PyInstaller 2手册

spec文件将是touchtracer.spec,位于pyinstaller+touchtracer目录内。现在我们需要编辑spec文件来添加kivy钩子以正确构建exe。使用您喜爱的编辑器打开等级库文件,并在等级库的开头添加以下行:

from kivy.tools.packaging.pyinstaller_hooks import install_hooks
install_hooks(globals())
cd pyinstaller-2.1
python pyinstaller.py touchtracer\touchtracer.spec
在分析函数中,删除hookspath=None参数。如果你不这样做,kivy软件包钩子将不会被使用

然后,您需要更改对方付费调用以添加touchtracer touchtracer.kv、particle.png等的数据。。。。更改行以添加树对象。此树将搜索touchtracer目录中找到的每个文件,并将其添加到最终包中:

coll = COLLECT( exe, Tree('../kivy/examples/demo/touchtracer/'),
               a.binaries,
               #...
               )
我们完了。您的规范已准备好执行

建立规范

双击Kivy.bat

转到pyinstaller目录,并构建规范:

from kivy.tools.packaging.pyinstaller_hooks import install_hooks
install_hooks(globals())
cd pyinstaller-2.1
python pyinstaller.py touchtracer\touchtracer.spec

包将位于touchtracer\dist\touchtracer目录中。

那么它是kivy应用程序吗?如果是这样的话,我刚才在Kivy IRC频道了解到,因为我使用了Christph Golke的预编译Windows二进制文件,所以它没有附带Kivy.bat,这是特定于平台的。相反,我需要正常启动一个命令shell。好的。。。我想。。。通常,kivy是一个打包python和其他东西的压缩包