簡體   English   中英

如何使用cx_Freeze制作可執行的python程序

[英]How to use cx_Freeze to make an executable python program

我下載了cx_Freeze,因為我試圖制作一個.exe文件與我的排共享,並且我一直在閱讀文檔以及在cx_Freeze教程中滾動。 跟隨這兩個之后,我仍然不知道為什么這對我不起作用。 我使用的是Python 3.6.2,我將路徑直接設置為命令行。

我嘗試在桌面上使用setup.py和Julian date 2.py啟動,並嘗試將它們添加到同一文件夾中,但是無論我嘗試什么,當我鍵入python setup.py build ,我都會收到此錯誤, python: can't open file 'setup.py': [Error2] no such file or directory or file exsists 以下是我的setup.py代碼。

from cx_Freeze import setup, Executable

setup(name = "Julian date 2" ,
    version = "0.1" ,
    description = "" ,
    executables = [Executable("Julian date 2.py")])

我遇到的另一個問題是嘗試鍵入cxfreeze Julian date 2.py --target-dir dist我得到錯誤'cxfreeze' is not recognized as an internal or external command, operable program or batch file.

  1. 當您鍵入python setup.py build時,應該位於setup.py目錄中,而不是其他任何位置。 因此,使用命令cd到達那里。

  2. cx_freeze不在您的路徑變量中,因此cxfreeze朱利安日期2.py --target-dir dist將不起作用,您必須(以某種方式)將其添加到您的路徑中[不推薦]

希望這會有所幫助。

PS可執行文件= [Executable(“朱利安日期2.py”)])也有基礎。 如果需要控制台應用程序:可執行文件= [Executable(“ Julian date 2.py”,base ='None')])Windows的Gui:可執行文件= [Executable(“ Julian date 2.py”,base ='Win32GUI' )])

而且您忘記了setup()中的exe選項。 我建議在cx_freeze doxs上修改setup.py腳本:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).

base = "None"

setup(  name = "name",
        version = "0.1",
        description = " ",
        options = {"build_exe": build_exe_options},
        executables = [Executable("file.py", base=base)])

我解決了第一個問題 ,我的文件名為“ setup.py”,而不僅僅是“ setup”,因為它應該是...名稱必須是擴展名,.py

下班后知道是啞巴,就是問題所在...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM