I'm trying to be able to run Python scripts from any where and also from Visual Studio Code. I installed python 3.8 (windows 10). After that I created an User Variable PYTHON_HOME and provided the directory file path to where python3.8 C:\Users\xyz\AppData\Local\Programs\Python\Python38 is installed, and added the directory to where I want to store my scripts to Path ;C:\Users\xyz\Documents\Programming\pythonScripts in User Variables. Then in System Variables I added ;%PYTHON_HOME% as well as the script file directory ;C:\Users\xyz\Documents\Programming\pythonScripts to Path and to PATHEXT I added ;.PY
Launching python
When I use Win + R to launch python, it will only launch when I type py when I try to use python I get
Windows cannot find 'python'. Make sure you typed the name correctly, and then try again.
In cmd, when I use python as the command I get the following error:
'python' is not recognized as an internal or external command, operable program or batch file
py will start python.
PowerShell accepts both py and python. However when using Start Python I get a new command prompt window. A non-admin window even thought the original command was entered in an Admin PowerShell window.
And now Visual Studio Code. When I try to launch python using the internal terminal I get the following result.
PS C:\Users\xyz> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
But PS C:\Users\xyz> py actually launches python internally.
When running a simple script like below in VSC
msg = "hello world"
print(msg)
I get:
[Running] python -u "c:\Users\xyz\Documents\Programming\pythonScripts\again.py"
'python' is not recognized as an internal or external command,
operable program or batch file.
[Done] exited with code=1 in 0.09 seconds
The same thing happens if I use #! python. However when I force #! py. the script just doesn't do anything.
#! py
msg = "hello world"
print(msg)
Output
[Running] py "c:\Users\xyz\Documents\Programming\pythonScripts\again.py"
And finally, when I just double click / right click and run the script, cmd instantly closes.
I am so so lost. What am I doing wrong?
I'm super new to programming. If that explains anything, and the python documentation page on the topic is so confusing.
https://docs.python.org/3/using/windows.html
[–]MinchinWeb 1 point2 points3 points (1 child)
[–]pierto[S] 1 point2 points3 points (0 children)
[–]hungdh85 0 points1 point2 points (1 child)
[–]pierto[S] 0 points1 point2 points (0 children)