I am trying to create a python file and then convert it into an EXE. This is my current code:
from cx_Freeze import setup, Executable
spyerFile = open("myFile.py", "w ")
spyerFile.write("print(\"Hello, world!\")") # creating the python file
spyerFile.close()
executables = [Executable("myFile.py", base=None)]
packages = ["idna", "os", "sys"]
options = {
"build_exe": {
"packages":packages,
},
}
setup( # converting the python file to an exe file
name = "myFile",
options = options,
version = "10.0",
description = "",
executables = executables
)
But I am getting this error:
usage: myFile.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: myFile.py --help [cmd1 cmd2 ...]
or: myFile.py --help-commands
or: myFile.py cmd --help
error: no commands supplied
Can someone please tell me what am I doing wrong?
CodePudding user response:
After taking a loot in the documentation: https://cx-freeze.readthedocs.io/en/latest/setup_script.html
I am guessing you just ran the file, but you actually need to run a specific command, depending on how you want to build it. This one should be perfect for most cases: python file_name.py build
CodePudding user response:
Assuming you have the script you posted in myScript.py, which creates myFile.py, you have to call it passing as an argument the build command:
python myScript.py build
Maybe you are using VSCode and just running your script by clicking the run button or something like that, which by default run your script without passing it any argument. Anyway, in VSCode and in probably any IDE you can modify this behaviour. In VSCode you can create a launch.json file and specify here the arguments you want to pass to your script.