+ 2

Powershell and cmd don't run my Python (. py) files

Hi, people, I hope that you are fine, I'm trying to run my Python (. py) files in Powershell and CMD using windows 10, I've already reinstalled Python three times and put the checkmark on the PATH part, i don't know exactly how, when or where I'm F up things but those files simply are not running, I saved the files on my Desktop with the .py extension, then I go to Powershell or Command Prompt and type md desktop, and try to run the file and nothing, when I type python in PS or CMD inside the terminal and run commands (inside them) are working without issues, I was reading some articles regarding the PATH, but I don't want to screw things on my computer, one error is "[Errno 22] Invalid argument". Thanks in advance, any help or assistance will be more than welcome.

22nd Jul 2020, 11:52 PM
Whally O.
Whally O. - avatar
20 Respuestas
+ 3
i use vs code and i use an easy way to compile my programs, try searching for code runner extension on vs code. you won't have to touch the terminal everytime you compile. another easy way to compile python is to simply write python / python3 on the terminal then drag the python file into the terminal. it wil automatically show the full directory and you can run it instantly.
23rd Jul 2020, 11:39 AM
Shen Bapiro
Shen Bapiro - avatar
+ 2
Ive tried and failed many times. I ended up making a batch file with a couple lines to run it. Just open a text file and type: c:\python27(or_whatever)\python.exe c:\path_to\somescript.py %* #add next line if its a program that just shows #output once @pause Then save the text file with a .bat extesnsion. when you double click it will run the script
23rd Jul 2020, 12:26 AM
Slick
Slick - avatar
+ 2
Yeah no worries. The first line is the full path to your python.exe the second line is the full path to your script AND %* after a space @pause goes in when you have a super simple program that just prints out the solution to an equation or some other one step process. it just pauses the screen so you can see the output. otherwise the window would just automatically close I would just find then in file explorer and copy paste the paths
23rd Jul 2020, 12:46 AM
Slick
Slick - avatar
+ 2
they may be running a different os
23rd Jul 2020, 12:48 AM
Slick
Slick - avatar
+ 2
Martin Taylor Thank you, it can be done in Powershell as well or only in CMD? I've put on CMD as an admin: C:\WINDOWS\system32> where python Then it shows this: C:\Users\MyName\AppData\Local\Programs\Python\Python38\python.exe and C:\Users\MyName\AppData\Local\Microsoft\WindowsApps\python.exe It returns those two lines together, I don't know what to do now, sorry.
23rd Jul 2020, 2:07 AM
Whally O.
Whally O. - avatar
+ 2
Martin Taylor 🤦🏾‍♂️, well thank you once again. Ok, first at all, you are saying that I have two Pythons installed in the AppData folder and both should be removed from my laptop by using Control Panel and add/remove programs and then reinstall Python using Administrator rights, I'm not sure how to install with administrator rights, so it has to be downloaded from windows store or python.org? Then you said to clean the path environment variables and reboot before reinstalling and use "run as administrator" when I run the setup program and install to C:\Python38, sorry I didn't get that either. Whenever you have time, please, verify my question.
23rd Jul 2020, 3:17 AM
Whally O.
Whally O. - avatar
+ 2
Martin Taylor Yes, you're right! I've one year learning Python and of course more about Windows, my solution on Powershell was to cd my user folder then cd Desktop and then the folder where I have the VS code .py files and then run the desired script , I know that is not the correct approach, but is working so far, thank you very much for your assistance, and yes it's again in AppData folder, 🤣
23rd Jul 2020, 4:42 AM
Whally O.
Whally O. - avatar
+ 2
Martin Taylor Thank you, man! Yes, I will stay away from Powershell , I will keep using the cmd better, I will try to learn more about System Admin in Windows and Linux, very useful commands you sent me, This " cd %USERPROFILE% or cd %userprofile%" has to be typed with the "%"? and by userprofile you mean that specific word or my name?
23rd Jul 2020, 5:33 AM
Whally O.
Whally O. - avatar
+ 2
Try Git Bash
23rd Jul 2020, 4:17 PM
John Daniels
John Daniels - avatar
+ 2
Download Git
23rd Jul 2020, 4:17 PM
John Daniels
John Daniels - avatar
+ 1
Martin Taylor Outstanding, simply great, thank you very much, I will verify those
23rd Jul 2020, 7:30 AM
Whally O.
Whally O. - avatar
0
Ethien It is the latest one, Python 3.8 something, thanks
23rd Jul 2020, 12:25 AM
Whally O.
Whally O. - avatar
0
Slick Thanks man! Sorry, would you say that again but slowly, please? Text file(I'm assuming notepad or something like that), c:\python27(in my case I think is python38), maybe So it's "c:\python38\python. exe" right? Then c:\path_to\somescript.py %* ☝🏾In that same way or do I need to change something? Then Add next line if it's a program that jusg shows output once @pause ☝🏾 Where that "@pause" goes? Thanks in advance!
23rd Jul 2020, 12:42 AM
Whally O.
Whally O. - avatar
0
Ethien Sorry, what was that again, I didn't get it? The most frustrating thing is that you see people online on tutorials, etc., and their .py scripts run just fine in the different terminals, 🤔🤣
23rd Jul 2020, 12:43 AM
Whally O.
Whally O. - avatar
23rd Jul 2020, 6:50 PM
Whally O.
Whally O. - avatar