Since, you are able to run Python in PowerShell. You can just do python <scriptName>.py to run the script. So, for a script named test.py containing
Copyname = raw_input("Enter your name: ")
print "Hello, " + name
The PowerShell session would be:
Start:
Copycd C:\Python27
python test.py
Session transcript:
CopyEnter your name: Monty Python
Hello, Monty Python
Answer from Sukrit Kalra on Stack OverflowSince, you are able to run Python in PowerShell. You can just do python <scriptName>.py to run the script. So, for a script named test.py containing
Copyname = raw_input("Enter your name: ")
print "Hello, " + name
The PowerShell session would be:
Start:
Copycd C:\Python27
python test.py
Session transcript:
CopyEnter your name: Monty Python
Hello, Monty Python
As far as I have understood your question, you have listed two issues.
Problem 1
You are not able to execute the Python scripts by double clicking the Python file in Windows.
Reason
The script runs too fast to be seen by the human eye.
Solution
Add input() in the bottom of your script and then try executing it with double click. Now the cmd will be open until you close it.
Example
Copyprint("Hello World")
input()
Problem 2
./ issue
Solution
Use Tab to autocomplete the filenames rather than manually typing the filename with ./ autocomplete automatically fills all this for you.
Usage
CD into the directory in which .py files are present and then assume the filename is test.py then type python te and then press Tab, it will be automatically converted to python ./test.py.
Powershell and python executables
Is it possible to run a Python script directly in VSCode or PowerShell with a custom command? I'm used to using the terminal (for PowerShell scripts) because it's super fast, is this possible with Python scripts?
Running a python script via Powershell script - Stack Overflow
Using PowerShell to execute a Python Script on a Linux server
How do I pass arguments from PowerShell to a Python script?
Can I integrate Python scripts into an MSI package?
Videos
Edit the PATHEXT environment variable and add the .py extension.
Just add this line to your PowerShell profile:
$env:PATHEXT += ";.py"
or you could just edit PATHEXT globally in the system settings (just search in the Start menu for "environment" and choose the option for "Edit environment variables for your account").
You might have more than one version of Python installed and the version IDLE is using is newer. To see what version of python you have you can type >python -V at a command line. If that version looks appropriate then you might need the full path to the file as the second parameter. E.g >python C:\myfile.py.
If you installed Python correctly there is always a chance that just typing the name of the script will run it with python. E.g. >myfile.py
I always find that adding C:\Python27 to the %PATH% variable and .PY to the %PATHEXT% variable makes running scripts easier. In this case just >myfile should work.
Edit after Update:
Typing just >python with no parameters opens python in 'interactive mode' which is different from the batch or scripting mode that your script is intended for. If executed with arguments the first argument is taken as the file path and further arguments are passed to the script in the sys.argv list.
Let's say you have a Python script that prompts the user for their name and then writes "Hi, {Name}"
Now in PowerShell this is super easy, I can create a custom function, throw it into my PowerShell $Profile, and set an alias (and call it something like Get-Name). Then, in VSCode I can simply type "Get-Name" without having to search for the program, open it, fiddle with it, etc. Meaning I can have any file open in VSCode and type Get-Name and it always works. As you can imagine, this is super fast and convenient.
How do I do the same thing with Python? Suppose the file is in c:/code/name.py, what would you do? Again the goal is so I don't have to constantly navigate through the folders, find the file, open it, click run, and then use it.
Assuming that python is already in your path variables you can just call a python script like this:
python C:\User\PythonScripts\TestFile.py
I think the question is you want to run the python script using powershell .
I think below code will do for you
$path = 'C:\User\PythonScripts'
$file = 'TestFile.py'
$cmd = $path+"\\"+$file # This line of code will create the concatenate the path and file
Start-Process $cmd # This line will execute the cmd
Save the above code as .ps1 and run the that powershell file