简体   繁体   English

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

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

I downloaded cx_Freeze because I'm trying to make a .exe file to share with my platoon and I've been reading through the docs as well as scrolling through cx_Freeze tutorial . 我下载了cx_Freeze,因为我试图制作一个.exe文件与我的排共享,并且我一直在阅读文档以及在cx_Freeze教程中滚动。 After following both of those I still don't know why this isn't working for me. 跟随这两个之后,我仍然不知道为什么这对我不起作用。 I'm on Python 3.6.2 and I have the path directly setup to the command line. 我使用的是Python 3.6.2,我将路径直接设置为命令行。

I tried to launch with setup.py and Julian date 2.py on the desktop and I tried adding them to same folder, but no matter what I try I get back this error when I type python setup.py build , python: can't open file 'setup.py': [Error2] no such file or directory or file exsists . 我尝试在桌面上使用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 Below is my setup.py code. 以下是我的setup.py代码。

from cx_Freeze import setup, Executable

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

Another issue I ran into was trying to type cxfreeze Julian date 2.py --target-dir dist I get the error 'cxfreeze' is not recognized as an internal or external command, operable program or batch file. 我遇到的另一个问题是尝试键入cxfreeze Julian date 2.py --target-dir dist我得到错误'cxfreeze' is not recognized as an internal or external command, operable program or batch file.

  1. When you type python setup.py build, you are supposed to be in the directory with setup.py and not anywhere else. 当您键入python setup.py build时,应该位于setup.py目录中,而不是其他任何位置。 So use the command cd to get there. 因此,使用命令cd到达那里。

  2. cx_freeze is not in your path variable so cxfreeze Julian date 2.py --target-dir dist will not work and you have to instead add it to your path (somehow) [not recommended] cx_freeze不在您的路径变量中,因此cxfreeze朱利安日期2.py --target-dir dist将不起作用,您必须(以某种方式)将其添加到您的路径中[不推荐]

Hope this helped. 希望这会有所帮助。

PS executables = [Executable("Julian date 2.py")]) takes base too. PS可执行文件= [Executable(“朱利安日期2.py”)])也有基础。 If you want a console application: executables = [Executable("Julian date 2.py",base='None')]) Gui for windows: executables = [Executable("Julian date 2.py",base='Win32GUI')]) 如果需要控制台应用程序:可执行文件= [Executable(“ Julian date 2.py”,base ='None')])Windows的Gui:可执行文件= [Executable(“ Julian date 2.py”,base ='Win32GUI' )])

And you forgot your exe options in setup(). 而且您忘记了setup()中的exe选项。 I recommend adapting the setup.py script on cx_freeze doxs: 我建议在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)])

I solved the first issue , my file was named 'setup.py' and not just 'setup' as it's supposed to be...The name must be setup, the extension .py 我解决了第一个问题 ,我的文件名为“ setup.py”,而不仅仅是“ setup”,因为它应该是...名称必须是扩展名,.py

Know it's DUMB, after hours, that was the problem... 下班后知道是哑巴,就是问题所在...

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

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