Command Prompt does not execute .py file correctly? - python

I use Adobe products (such as Premiere Pro/Photoshop) a lot and wanted to have Discord Rich Presence implementation.
I found a very useful python script for this: https://github.com/smokes/adobe-rpc
If I manually execute it (opens command prompt) it works perfectly fine, it detects my Discord and Premiere Pro/Photoshop and displays it correctly in Discord.
However I wanted to run this script when I launch Premiere Pro/Photoshop so I used a batch file for this:
#echo off
start "Premiere Pro" "C:\Program Files\Adobe\Adobe Premiere Pro CC 2019\Adobe Premiere Pro.exe"
ping -n 20 localhost
python "E:\Software\Python\Adobe Discord Rich Presence\adobe-rpc-master\rpc.py"
It opens the script as it should but when it actually launches the script, the script can not find Discord or the Adobe software.
It just states "Run Adobe/Discord App".
I have tested the script by opening a fresh Command Prompt and dragging the script in: same result as stated above. It can not find Discord or the Adobe software.
This is very strange to me as I can perfectly run it if I open it manually but not if I run it in the Command Prompt?
Furthermore, Python does not give an actual error message, just the "error message" that is built inside the script.
When I launch it manually, it opens in the Command Prompt so I am very confused as to why this happens.
Can anyone explain this/help me?
I am very new to the Command Prompt and Python.

Warning! This is comment and maybe answer both!
First of all: do you have Python 3.4>= added in PATH? If not add.
Second: Do you followed instructions in README.md? If not follow!
Third: Which Adoble application do you use and is it available in adobe-rpc's repository? If not then wait for next update of adobe-rpc.
Fourth: Try to open script in it's directory and this is how:
Go to script's folder
Hold SHIFT and click RMB, also called Right Button Mouse. In menu Open Command Prompt here or Open Powershell here must be displayed.
If Open Command Prompt here is displayed instead of Open Powershell here, click it.
Now do: python scriptname.py ~ I don't know that script usage and if it requires arguments, just do python scriptname.py arguments.
If Open Powershell here is displayed instead of Open Command Prompt here. Go back, but first copy directory.
Then press WIN+R and in Run input type cmd.
In Command Prompt(CMD) type cd and paste your directory, then hit Enter.
Now do same as in 4. line.
Maybe this would help.
Otherwise I don't know.

Related

How to run Python scripts in Visual Studio Code with Code Runner in a Windows command prompt while showing errors in integrated panel?

By default, running a .py file through VSCode Code Runner executes the program in the VSCode integrated terminal:
I would like it to do exactly what it does in the integrated terminal, but launch the code through a separate Windows command prompt, like PyCharm.
If I go into settings.json in VSCode, I could change "code-runner.runInTerminal": true, to false, it will execute the code in the output tab instead of terminal tab.
This doesn't help me much.
From settings.json I can change:
to:
This executes the program in the external terminal I want, but it has some serious drawbacks. For one, I have to add input() at the end of my code every time in order for it not to automatically close. The bigger problem is that if I have some kind of logical error in my code, it won't show me any type of error message; just closes the command prompt.
Is there any way to have the code execute in an external Windows command prompt, show all error messages (either in VSCode or terminal itself), and have the terminal require input to close without needing the input() function at the end of my code?
You can open windows terminal/command prompt from the start menu, navigate to your python file and use the same python command to run the python file that you used in VSCode.
[enter image description here][1]
You won't need to add "input()" to your code and you will also get tracebacks.
EDIT: reuploaded picture.
[1]: https://i.stack.imgur.com/qzQz2.png

How to make Windows execute my Python script files when I click them

I have made a Python program that uses output.to_csv('results.csv'). When I run it in Spyder it creates that CSV file. But when I double click on it nothing happens. Cmd appears and closes but nothing on the folder, no results.csv.
What am I missing? What more do I have to do?
Run the program from the command line itself instead of double-clicking the .py file.
I assume you are on Windows since you mention CMD. First, cd into the directory containing your program. Then, run python <program>.py or python3 <program>.py depending on your installation.
This time, you will see any output or error messages that appear in CMD without it immediately closing.
If the .csv file really exists, you should be able to go to your File Explorer and find the file at the top of the "Quick Access" section. Right-click the file and hover over "Open With >". Then select Notepad and a notepad will open up showing your results.
If you do not see the file, then try running your program on the command prompt (for Windows):
Press the windows key and type "cmd" in the search bar.
Choose "Command Prompt"
Go to the dir of your program using the cd command
Type python <program name>.py
If there are no errors, follow the steps in the first paragraph.
Ok i guess windows is not recommended at all for this type of tasks. I mean running something simple as create such file is like trying to kill the Lernaean Hydra.
What i did is i just runned it with anaconda prompt and it worked sweet! Thanks for help. Thanks to all!
PS: I'm seriously considering changing to Linux after this
For anyone having the same problem, but have anaconda installed. 1) Open Anaconda Prompt, 2) use cd (1 space) then adress of the folder which contains your py program (eg. cd C:\Users\Bernie\Desktop\tasos) and hit enter, 3) on the next line that appears type: python program_name.py, 4)Hit enter, 5)success!

Python py not executing in other PC

I have a technical questions on python script.
I have developed code on my laptop and I want to move it in another one.
I installed python there, put when I try to double click on the .py file it is not working. Like the cmd screen goes away in a second.
Do you know why?
(if I open python through cmd it is working, so it is in path and it works)
What is probably happening is that there is an error being thrown on your new computer which causes command prompt to just instantly close.
The best way to run a python script is from an open command prompt/terminal. To do this open a command prompt and move into the directory of your python file. For example, if the file you are trying to run is located at C:\Users\Davide\PythonScripts, then open a command prompt and type
cd C:\Users\Davide\PythonScripts
Now your command window is in the folder that you want to run files out of.
Next you want to tell Python to run your script. This can be done by typing "python ". For example, if your script is name my_script.py, you would type
python my_script.py
What this is doing is telling your computer "open an instance of Python where you are running my_script.py." If there are any errors thrown, the command window will stay open after python closes and you can see what is going on.
Most likely, there is a package you are trying to import which it cannot find because it was not installed on your other computer. If at the top of your file you have "import xxx" or "from xxx import yyy" lines, your other computer might not be finding those modules and just throwing an error that instantly closes command prompt when you just double click the .py file.

Cannot run a Python file from cmd line

I have installed Python and written a program in Notepad++.
Now when I try to type the Python file name in the Run window, all that I see is a black window opening for a second and then closing.
I cant run the file at all, how can run this file?
Also I want to tell that I also tried to be in the same directory as a particular Python file but no success.
I assume you are running the script with command python file_name.py.
You can prevent closing of the cmd by getting a character from user.
use raw_input() function to get a character (which probably could be an enter).
It sounds like you are entering your script name directly into the Windows Run prompt (possibly Windows XP?). This will launch Python in a black command prompt window and run your script. As soon as the script finishes, the command prompt window will automatically close.
You have a number of alternatives:
First manually start a command prompt by just typing cmd in the Run window. From here you can change to the directory you want and run your Python script.
Create a Windows shortcut on the desktop. Right click on the desktop and select New > Shortcut. Here you can enter your script name as python -i script.py, and a name for the shortcut. After finishing, right click on your new shortcut on the desktop and select Properties, you can now specify the folder you want to run the script from. When the script completes, the Python shell will remain open until you exit it.
As you are using Notepad++, you could consider installing the Notepad++ NppExec plugin which would let you run your script inside Notepad++. The output would then be displayed in a console output window inside Notepad++.
As mentioned, you can add something to your script to stop it completing (and automatically closing the window), adding the line raw_input() to the last line in your script will cause the Window to stay open until Enter is pressed.
Try to open in Command Prompt instead of run window. The syntax is:
py filename.py
If it doesn't work, try to reconfigure Python. Did you set environment variables? If not, this could help you

Python command-line mode error

I have some difficulties trying to run the python programs from cmd, or command-line. When i double click the python program it display the cmd for some seconds in fact less than 3 Seconds, and cmd disappeared. I can only run by right clicking on it then edit in idle and run model command. Only from the python shell. And how to give path for python shell to find applications, for instance just type the program name and it runs. Do python have GUI as exe programs?
First make sure python.exe is in your path.
Then type in the command prompt (cmd) python "path\to\program.py"
If you want to just type the progam name, you have two options.
Add the folder containing your program to your path.
Right click in the folder while holding shift, and then click "open command prompt here"

Categories