How to run python in exe window - python

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.

Related

Fail to run the exectuable via cmd or Python

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.

Running a Python Exe through Excel / Command Prompt can't find file but running it normally in file explorer works

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?

How to run a Python file from a Batch File with Anaconda prompt on Windows 10?

I created a script in python and I need it to run in way that the python code is not visible. I tried different methods like implementing nodeJS and PHP, but to no avail. So, I thought of using a .bat file to run the python file. I created a bat file for the python script, but on clicking the batch file all I got was an error saying that a module was missing in the code. The code works perfectly when I run it in Spyder and on the Anaconda Prompt. So, I thought of running the file from a batch file via the Anaconda Prompt. The code in the batch file is below:
%windir%\System32\cmd.exe /K ""C:\Program Files\Anaconda3\Scripts\activate.bat" "C:\Program Files\Anaconda3""
python myscript.py
pause
The .bat file now opens a command prompt in the python environment, but does not run the python file. I tried altering the code, but it was always the same result. If I type:
python myscript.py
into the next line in the command prompt, the python file gets executed. I need to find a way for the file to be executed without typing anything in the prompt. The python file contains GUI from tkinter and the shebang line has the python version (3.7.4). I work with Windows 10.
I tried this code in the batch file as well,
"C:\Program Files\Anaconda3\python.exe" "C:\Users\Sathya\Desktop\myscript.py"
pause
All this did was open and close the command prompt in the blink of an eye. I tried to run the bat file a few more times, but got the same result. But, this code worked on a different file (also with tkinter GUI) myscript_test.py and this one gave the GUI window correctly. I don't have a clue as to why it worked on the second one and not the first one.

Keep error message of exe file which is created by Pyinstaller

I am using Pyinstaller to create exe file from Python source code, and I keep the cmd window when the exe is running
python pyinstaller.py --onefile script.py
Whenever there is an error, the error shows on the cmd window but disappears very quickly, is there any way to keep the error message on the cmd window?
Create a batch file. Inside of it, put:
C:\path\to\your\file.exe
pause
and double click the batch file. Alternatively, just open a cmd window, navigate to the directory containing the exe and run yourExe.exe.

The output of a python script

So I am trying to debug some Python code that I am running, because for some reason when I run the code in a command line it works perfectly, but when I make it a .py file and run it that way it fails.
The output is in a Windows Commander window, and it disappears before I can read it.
Is there a way to see what this output is?
Open a windows commander, and then go to the dir where a.py is, run "python a.py", it will not disappear!

Categories

Resources