My tutor sent me an executable to run the simulation. The usage is to put the executable, settings files and initial files to the same folder and double click the executable, and the executable will generate the result text file.
Recently I try to integrate this function into my python script. The goal is when I run the python script, the script could generate the basic input file in the folder and then run the executable to generate the result. A part of the script looks like this:
path_exe = r"D:\direction\xxx.exe"
subprocess.run(path_exe,shell=True)
However, it returns:
ERROR LOADING Keyfile_0 FILE
I'm sure that the "keyfile" is in the same direction, because it works well when I double click the executable.
Then I try to run it via cmd. I drag the executable into cmd window and press enter, the same error happens.
I don't know if it is blamed on the executable, or is the code error.
I have a python script which I have turned into an Exe with the hope of running it through Excel VBA. As the first line, it attempts to load in a csv file with
inputs = pd.read_csv("file.csv") Where file.csv is a data file in the same directory.
When I turn it into an exe it works when I try to run it through double clicking in File Explorer, however when I tried to run it through Excel using the Shell Command I get the error saying it cannot find the file.csv (FileNotFoundError). I figured out that the same thing occurs when I try to run the exe using Command Prompt.
Any ideas why this would be happening?
I used this (python -m nuitka --follow-imports program.py) command to compile my script using Nuitka . It made an .exe file which worked quite well for me other than --onefile commands , as they were showing me import error. But here the problem is , a cmd console opens up of my .exe file after is start it, then my tkinter gui console shows up. I tried to use .pyw file to compile my script, but it didn't help me. I need help to shutdown or hide that cmd console window which pops up for my .exe file.
I have a python code file named testcode.py and I have open a python.exe window open in order to run the code. I read online that I would run the code by putting
python testcode.py
into the exe window but it is saying that a syntax error and points to the name of my py file. Is there a reason why this is happening? Does the py file need to be saved in a certain place?
You're getting an error because you're trying to run shell code in the Python interpreter. Open a CMD or PowerShell window and run python testcode.py there.
I want to make my program executable.
I used TkInter to write the GUI, and I read somewhere that you have to save your file as .pyw to hide the console when the program is executed.
The problem is that after making it an executable with PyInstaller, the console shows up again, even though the file converted was .pyw.
How can I hide the console also in the .exe file?
Did you try --windowed command line flag ?
You can just save the file with .pyw extension and you can just use pyinstaller --onefile Filename.pyw
I think you renamed it. You save it as .pyw don't rename it.
The screenshot are below:
Output:
But it takes a while to open.
Thank you
-Levers
What are you using to make the executable?
If you use py2exe and you use:
setup(windows=[pythonscriptnamehere])
in the setup script instead of:
setup(console=[pythonscriptnamehere])
it will run the executable without launching a terminal in the background.
From The PyInstaller Documentation:
Using a Console Window
By default the bootloader creates a command-line console (a terminal
window in GNU/Linux and Mac OS, a command window in Windows). It gives
this window to the Python interpreter for its standard input and
output. Your script’s use of print and input() are directed here.
Error messages from Python and default logging output also appear in
the console window.
An option for Windows and Mac OS is to tell PyInstaller to not provide
a console window. The bootloader starts Python with no target for
standard output or input. Do this when your script has a graphical
interface for user input and can properly report its own diagnostics.
As noted in the CPython tutorial Appendix, for Windows a file
extention of .pyw suppresses the console window that normally appears.
Likewise, a console window will not be provided when using a
myscript.pyw script with PyInstaller.
Rather than saving/renaming/changing the extension to .pyw, you can just add --noconsole to the command line and use the standard .py file with it and this would hide that console window.
Example:
We have a file named GUI_name.py in our folder that uses Tkinter. Now we could easily create .exe file that doesn't show the console window by typing pyinstaller --onefile --noconsole GUI_name.py in cmd.