<small id='iDUzF'></small><noframes id='iDUzF'>

    <bdo id='iDUzF'></bdo><ul id='iDUzF'></ul>

      <i id='iDUzF'><tr id='iDUzF'><dt id='iDUzF'><q id='iDUzF'><span id='iDUzF'><b id='iDUzF'><form id='iDUzF'><ins id='iDUzF'></ins><ul id='iDUzF'></ul><sub id='iDUzF'></sub></form><legend id='iDUzF'></legend><bdo id='iDUzF'><pre id='iDUzF'><center id='iDUzF'></center></pre></bdo></b><th id='iDUzF'></th></span></q></dt></tr></i><div id='iDUzF'><tfoot id='iDUzF'></tfoot><dl id='iDUzF'><fieldset id='iDUzF'></fieldset></dl></div>

      <tfoot id='iDUzF'></tfoot><legend id='iDUzF'><style id='iDUzF'><dir id='iDUzF'><q id='iDUzF'></q></dir></style></legend>

    1. 在 Windows 10 上使用 Nuitka 将 Python 3.6 脚本编译为独

      时间:2023-10-08
          <bdo id='uhUN8'></bdo><ul id='uhUN8'></ul>

          <small id='uhUN8'></small><noframes id='uhUN8'>

          • <legend id='uhUN8'><style id='uhUN8'><dir id='uhUN8'><q id='uhUN8'></q></dir></style></legend>
              <tbody id='uhUN8'></tbody>

            <tfoot id='uhUN8'></tfoot>

              <i id='uhUN8'><tr id='uhUN8'><dt id='uhUN8'><q id='uhUN8'><span id='uhUN8'><b id='uhUN8'><form id='uhUN8'><ins id='uhUN8'></ins><ul id='uhUN8'></ul><sub id='uhUN8'></sub></form><legend id='uhUN8'></legend><bdo id='uhUN8'><pre id='uhUN8'><center id='uhUN8'></center></pre></bdo></b><th id='uhUN8'></th></span></q></dt></tr></i><div id='uhUN8'><tfoot id='uhUN8'></tfoot><dl id='uhUN8'><fieldset id='uhUN8'></fieldset></dl></div>
              1. 本文介绍了在 Windows 10 上使用 Nuitka 将 Python 3.6 脚本编译为独立 exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                注意:
                在将此问题标记为重复之前,请验证其他问题是否回答了此设置的主题:

                Note:
                Before marking this question as duplicate, please verify that the other question answers the topic for this setup:

                • 操作系统:Windows 10,64 位
                • Python 版本:3.6 或更高版本
                • Python 编译器:Nuitka,开发版本 0.5.30rc5
                • MSVC 编译器:Visual Studio 2017 社区,vcvars64.bat

                 

                我将首先解释如何构建我的可执行文件.假设我有一个文件夹,里面有一个我想要构建的简单 python 脚本:

                I'll first explain how I build my executable. Suppose I have a folder with a simple python script that I want to build:

                buildscript.py 看起来像这样:

                #####################################################
                #               NUITKA BUILD SCRIPT                 #
                #####################################################
                # Author: Matic Kukovec
                # Date: April 2018
                
                import os
                import platform
                
                
                NUITKA = "C:/Python36/Scripts/nuitka3-script.py"  # Path where my nuitka3-script.py is
                CWD = os.getcwd().replace("\", "/")
                MSVC = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build/vcvars64.bat"
                PYTHON_VERSION = "3.6"
                PYTHON_EXE_PATH= "C:/Python36/python.exe"
                NUMBER_OF_CORES_FOR_COMPILATION = 1 # 1 is the safest choice, but you can try more
                
                # Generate command
                command = '"{}" amd64 &'.format(MSVC)
                command += "{} ".format(PYTHON_EXE_PATH)
                command += "{} ".format(NUITKA)
                command += "--python-version={} ".format(PYTHON_VERSION)
                command += "--output-dir={}/output ".format(CWD)
                command += "--verbose "
                command += "--jobs={} ".format(NUMBER_OF_CORES_FOR_COMPILATION)
                command += "--show-scons "
                # command += "--windows-disable-console "
                # command += "--icon={}/myicon.ico ".format(CWD)
                command += "--standalone "
                # command += "--run "
                command += "{}/cubeimporter.py ".format(CWD)
                os.system(command)
                
                print("END")
                

                 

                构建完成后,文件夹如下所示(见下图).如您所见,可执行文件旁边还有许多其他文件.我可以看到 .dll.pyd 文件.

                After the build finishes, the folder looks like this (see picture below). As you can see, there are plenty of other files sitting next to the executable. I can see .dll and .pyd files.

                 

                我希望我可以只构建一个独立的可执行文件.不需要 dll 或其他文件.当我将可执行文件放在拇指驱动器上并将其粘贴到另一台计算机(运行 Windows 10、64 位)时,它应该可以正常工作.即使那台计算机上没有安装 Python.

                I wish I could build just a standalone executable. No dll- or other files needed. When I put the executable on a thumb drive and stick it into another computer (running Windows 10, 64-bit), it should just work. Even if there is no Python installed on that computer.

                Nuitka 可以做到这一点吗?
                如果不是,是否可以使用另一个 Python 编译器?
                请一一提供所有需要的步骤:-)

                Is this possible with Nuitka?
                If no, is it possible with another Python compiler?
                Please provide all the steps needed, one-by-one :-)

                推荐答案

                单个可执行文件比 Nuitka 更容易,例如PyInstaller:pyinstaller --onefile program.py(要禁用 GUI 应用程序的控制台窗口,请添加 -w 选项.

                Easier than Nuitka for a single executable is e.g. PyInstaller: pyinstaller --onefile program.py (to disable the console window for GUI applications add the -w option).

                要使用 Nuitka 创建单个可执行文件,您可以从生成的文件创建 SFX 存档.您可以使用生成 program_dist 目录的 --standalone 选项运行 Nuitka.

                To create a single executable with Nuitka, you can create a SFX archive from the generated files. You can run Nuitka with the --standalone option which generates a program_dist directory.

                然后创建一个 7-Zip SFX 配置文件 config.txt:<代码>;!@Install@!UTF-8!GUIMode="2"ExecuteFile="%%T/program_dist/program.exe";!@InstallEnd@!

                Create then a 7-Zip SFX config file config.txt: ;!@Install@!UTF-8! GUIMode="2" ExecuteFile="%%T/program_dist/program.exe" ;!@InstallEnd@!

                然后从 https://github.com/chrislake/7zsfxmm 获取 7-Zip SFX (从版本 - 7zsd_extra_171_3901.7z)并解压 7zsd_All_x64.sfx 文件.

                Then get the 7-Zip SFX from https://github.com/chrislake/7zsfxmm (from releases – 7zsd_extra_171_3901.7z) and unpack the 7zsd_All_x64.sfx file.

                然后将 program_dist 与 7-Zip(因此该文件夹包含在存档中)打包到 program.7z.然后,可以使用 copy/b 7zsd_All_x64.sfx + config.txt + program.7z single_executable.exe 创建 SFX.

                Pack then the program_dist with 7-Zip (so the folder is included in the archive) to program.7z. Then, an SFX can be created with copy /b 7zsd_All_x64.sfx + config.txt + program.7z single_executable.exe.

                在 Unix 上,你也可以自己创建一个 SFX,如果你创建一个 tar 存档并将它附加到一个 shell 脚本中,它会提取并解压缩它,详情请参阅 https://www.linuxjournal.com/node/1005818.

                On Unix, you can also create yourself an SFX if you create a tar archive and append it to a shell script which extract it and unpack it, for details see https://www.linuxjournal.com/node/1005818.

                这篇关于在 Windows 10 上使用 Nuitka 将 Python 3.6 脚本编译为独立 exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:创建 venv 时出错,错误:命令 '-Im'、'en 下一篇:Selenium:WebDriverException:Chrome 无法启动:由于 google

                相关文章

                最新文章

                <tfoot id='Ec8aS'></tfoot>
              2. <small id='Ec8aS'></small><noframes id='Ec8aS'>

                  <legend id='Ec8aS'><style id='Ec8aS'><dir id='Ec8aS'><q id='Ec8aS'></q></dir></style></legend>

                1. <i id='Ec8aS'><tr id='Ec8aS'><dt id='Ec8aS'><q id='Ec8aS'><span id='Ec8aS'><b id='Ec8aS'><form id='Ec8aS'><ins id='Ec8aS'></ins><ul id='Ec8aS'></ul><sub id='Ec8aS'></sub></form><legend id='Ec8aS'></legend><bdo id='Ec8aS'><pre id='Ec8aS'><center id='Ec8aS'></center></pre></bdo></b><th id='Ec8aS'></th></span></q></dt></tr></i><div id='Ec8aS'><tfoot id='Ec8aS'></tfoot><dl id='Ec8aS'><fieldset id='Ec8aS'></fieldset></dl></div>
                      <bdo id='Ec8aS'></bdo><ul id='Ec8aS'></ul>