Why does cmd and powershell recognize "python" but not "py"? - python-3.x

I seem to be having the opposite issue as this user in this question. I can run python successfully, but py does not work for me. Overall, this is not a big deal but when I try to run code in VS Code, I get the error below:
py: The term 'py' is not recognized as a name of a cmdlet, function, script file, or executable program.
How can I either make VScode run python or change my system to accept py?
When I first downloaded Python, it was not placed into the path but I was able to fix that. I also confirmed that VS Code has selected the correct interpreter for Python in the same place.
EDIT: IMAGES
Path directory
Path used in enviroment

When you write "python" on CMD or Powershell, it checks the given keyword("python" here) in all the directories in Environment Variables.
In the case of python, the directory mentioned for python in Environment Variables > Path, you will find "python.exe" and not "py.exe".
So your cmd or PowerShell recognizes python and not py.

Related

I cannot run pyinstaller on my computer even though I have installed it

This is the problem right here, do you have any advice for that?
installed pip and pyinstaller, but still got this error message when I tried to convert my project into an .exe.
From Pyinstaller installation guide:
If you cannot use the pyinstaller command due to the scripts directory not being in PATH, you can instead invoke the PyInstaller module, by running python -m PyInstaller (pay attention to the module name, which is case sensitive). This form of invocation is also useful when you have PyInstaller installed in multiple python environments, and you cannot be sure from which installation the pyinstaller command will be ran.
So you may run it as e.g.:
python -m PyInstaller some_system.py
Or, as the issue seems that PATH Windows environment variable doesn't include Python's Script folder, it'd better to fix it. From the same guide:
If the command is not found, make sure the execution path includes the proper directory:
Windows: C:\PythonXY\Scripts where XY stands for the major and minor Python version number, for example C:\Python38\Scripts for Python 3.8)
To fix you may run where python to get exact location of Python on your machine (let's say it shows C:\Python38\). Then add to PATH env variable Scripts folder inside it (in this example it'd be C:\Python38\Scripts\)

Why am I not able to receive output when running python code in VSCode?

I have tried to print simple messages like "Hello World!" but have always been met with: [Running] python -u "/Users/user/HelloWorld!!/app.py"
/bin/sh: python: command not found
[Done] exited with code=127 in 0.176 seconds
enter image description here
Is there any way to get passed this error?
Check environment variable PATH
Every time you as a user run a command on your console, the machine looks for its location, or address, inside a list of predefined directories that are stored inside the environment variable PATH.
Such design helps to properly run the program or command without having to specify the absolute path on the terminal.
The environment variable PATH can be modified temporarily for the current terminal session, or permanently.
For windows/mac/linux
AND
Go to the VS Code preferences, and under interpreter, you'll find Interpreter Path, so set that to the path of your python installation, restart VS Code, and you should be good.

Cant Install pipx or Brownie for Python

I am very new with coding and was following along with these youtube videos and quickly realized something wasn't right, so I did some trouble shooting and couldn't figure it out.
When I tried to download pipx on VS Code I get this error
Python3 : The term 'Python3' 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.
I changed my environment variables, changed app execution aliases, and still nothing
I figured I'd check to see if python was working through VS Code and I get the same error
I tried downloading python through Microsoft store to see if that would help but nope.
Not sure what to do
I was having the same issue for a while even though I added the following directory to the environment variable and system variable. C:\Users\username\AppData\Roaming\Python\Python310\site-packages\pipx
What worked for me was adding the following directory to the environment variable and system variable. (c:\users\username.local\bin)
The directory (c:\users\username.local\bin) will be used to create the virtual environments.
I also found this when typing (python -m pipx ensurepath) which returned:
C:\Users\username\.local\bin has been been added to PATH, but you need to open a new terminal or re-login for this PATH change
to take effect.
C:\Users\username\AppData\Roaming\Python\Python310\Scripts has been been added to PATH, but you need to open a new terminal or
re-login for this PATH change to take effect.
The (C:\Users\username.local\bin) path was the only thing I did not manually enter into my environment variable and system variable, so thought I should give that a try and it worked.

Edit System Environment Variable Using Python

I was trying to add python path to the system evironment path by python.
I've tried
os.eviron['Path'] += ';C:/Anaconda3/'
However, I found this only make a difference in the script. I checked the system and didn't find ;C:/Anaconda3/ in the environment variable 'Path', which makes command python xxx.py can not be recognized by the system.
Is there any function or method to edit the system evironment path by python?
Could it be the spelling from environ to eviron?
or...
Maybe a quick batch script could help you do the trick as advised here. In the same question, you can find a way to do in python which would not survive a reboot here, but could do the trick.

Linux shell commands not found even though their paths are listed in the PATH variable

The google app engine cli commands cannot be found in the python sdk. I've already checked the google_appengine file. The shell commands are there, and I already added the app engine file path to the PATH variable. I echo the PATH variable and the directory to the app_engine file shows up, but still shows not found when I try to use a command that's inside the file. If I reference the command directly by using its whole path, the command works, but otherwise it won't. Is there anything else that needs to be done to reference a command in shell?
More error info please,
If I reference the command directly by using its whole path, the command works
I think your python path maybe wrong, Python 2.6 is not supported.
so are you have mulit-version python?
Thank you for your contributions everyone. It turns out the path I was using was wrong. Instead of /home/Programs/Apps/google_appengine it should have been /home/Programs/google_appengine. I guess the shell doesn't check to see if the path you add to the PATH variable actually exists. Who knew? Not me
Until I run into another problem stack overflow--which may be soon
See ya

Resources