This question already has answers here:
"python" not recognized as a command
(14 answers)
Closed 2 years ago.
So I have recently installed Python Version 2.7.5 and I have made a little loop thing with it but the problem is, when I go to cmd and type python testloop.py I get the error:
'python' is not recognized as an internal or external command
I have tried setting the path but no avail.
Here is my path:
C:\Program Files\Python27
As you can see, this is where my Python is installed. I don't know what else to do. Can someone help?
Try "py" instead of "python" from command line:
C:\Users\Cpsa>py
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
I have found the answer... click on the installer and check the box "Add python to environment variables" DO NOT uninstall the old one rather click on modify....Click on link for picture...
You need to add that folder to your Windows Path:
https://docs.python.org/2/using/windows.html Taken from this question.
If you want to see python version then you should use py -V instead of python -V
C:\Users\ghasan>py -V
Python 3.7.1
If you want to go to python's running environment then you should use py instead of python
C:\Users\ghasan>py
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Here you can run the python program as:
print('Hello Python')
Hello Python
Firstly, be sure where your python directory. It is normally in C:\Python27. If yours is different then change it from the below command.
If after you install it python still isn’t recognized, then in PowerShell enter this:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27",
"User")
Close PowerShell and then start it again to make sure Python now runs. If it doesn’t,
restart may be required.
Type py -v instead of python -v in command prompt
i solved this by running CMD in administration mode, so try this.
Open CMD with administrative access(Right click then run as administrator) then type the following command there:
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
Replace My_python_lib with the folder name of your installed python like for me it was C:\python27.
Then to check if the path variable is set, type echo %PATH% you'll see your python part in the end. Hence now python is accessible.
From this tutorial
I have installed python 3.7.4. First, I tried python in my command prompt. It was saying that 'Python is not recognized command......'. Then I tried 'py' command and it works.
My sample command is:
py hacker.py
I have met same issue when I install Python, and it is resolved when I set a PATH in system, here are the steps.
Navigate to "Control Panel" -> "System"
Click "Advanced system settings" on the left
Click "Environment Variables"
Search and click "Path" variable
Click "Edit"
Add "C:\"to the environment variables field, if you are using Windows7, then separate it by a semicolon from the existing entry. If you are using Windows10, just simply click "New" to add.
Reopen the Command Prompt and try
enter image description here
From the Python docs, set the PATH like you did as above.
You should arrange for Python’s installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python27. Otherwise you will be reduced to a search of your whole disk
Use Tools ‣ Find or hit the Search button and look for “python.exe”. Supposing you discover that Python is installed in the C:\Python27 directory (the default at the time of writing), you should make sure that entering the command
Then execute the Python command using the full path name to make sure that works.
Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.
If you uninstalled then re-installed, and running 'python' in CLI, make sure to open a new CMD after your installation for 'python' to be recognized. 'py' will probably be recognized with an old CLI because its not tied to any version.
Option 1 : Select on add environment var during installation
Option 2 : Go to C:\Users-> AppData (hidden file) -> Local\Programs\Python\Python38-32(depends on version installed)\Scripts
Copy path and add to env vars path.
For me this path worked : C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts
It was a bit more confusing with the Python instructions once SQL Server 2019 was installed with Python. The actual path I find is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
Scripts run with an Execute command:
Declare #script nvarchar(max)=N'print(11-2)' execute sp_execute_external_script #language = N'Python', #script = #script
There is additional documentation in reference to SQL 2019's version of Python. There is a statement that recommends PIP be used only from a download of sqlmutils-x.x.x.zip located on git (https://www.github.com/Microsoft/sqlmutils) But there is a caveat. Currently this only works for R and not for Python (Anaconda and consequently pip). Python over SQL works but pip is not yet available. (11/25/2019)
Would be great to get an update when this occurs.
Related
I have Plex installed on my PC, which relies on Python to run. I know nothing about Python, but I can see that it is running in Windows Task Manager. Now, I've got some other unrelated Python scripts that I need to run, but I have no idea how to find where Python is located on my system or how to access it.
According to How can I find where Python is installed on Windows?, I'm supposed to go to my Python interpreter to find out, but I have no idea what or where that is.
This is completely new to me. Could someone hold my hand and walk me through how I can run .py files?
Plex provides their own python libraries. This is built on Python 2.7. You do not need Python installed in order to run Plex and it's not recommended to use 2.7 at this point. You also cannot use the Python version provided by Plex, in the way you are hoping, as they don't include the executable.
Inside the installation directory of Plex you will see two files.
python27.dll
python27.zip
The contents of the zip folder are very close to the Lib folder from a standard installation of Python 2.7.
None of the provided solutions worked for you because python was not installed or available on your system path. Python can be installed by downloading it directly from Python (https://www.python.org/downloads/), executing the downloaded file, and following the prompts.
An alternative way to install Python is from the Microsoft Store, for Windows.
I will assume you are running on windows,so all you have to do is go to the Window's search option and search Python and you will there is python and then you just have to click it and click on open file location and then you will find the folder of it and your desired python version will be there.Then you just have to left click to go to the properties of it and click on open file location and you will find where you'r python is located and i will assume your python is most likely in the AppData\Local\Programes\Python folder :)
In windows: open the command prompt and type python, if it is set in your environment variables (which it asks while installation) it will open the python interpreter.
C:\WINDOWS\system32>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
for checking other files and modules, try on interpreter below.
>>> import sys
>>>
>>> print(sys.path)
To execute a python file. Simply open the command prompt and go to the location of the file and type python <name_of_python_file>
Python should be located at C:\Program Files\Python Are you trying to run py files through Command Prompt (CMD) or WindowsPowershell ? If yes then you can move to the directory, where your py files are located and just type the name of the py file in your terminal, to run it.
If you still cant find the directory, you can use a python interpreter and write:
(you can also open python in CMD by typing python then write the code below line by line,hitting enter after each line)
import os
import sys
print(os.path.dirname(sys.executable))
In Command Prompt(CMD) use cd path_name(f.example desktop) to move in directory, and cd .. to move back. Then you can us dir to see a list of the files in that directory , and simply type the name of your file for example python_file and hit enter to run it.
(Syntax might differ in WindowsPowershell)
None of the suggestions for finding where Python was installed worked.
As #tdelaney mentioned in the comments, even though Plex uses Python and it's running in my system, I don't actually have a standard install of it. I had to go download it.
I'm using arch linux and I've installed Anaconda as per the instruction on the Anaconda site. When I'm attempting to run conda info --envs I get the following error:
bash: /home/lukasz/anaconda3/bin/conda:
/opt/anaconda1anaconda2anaconda3/bin/python: bad interpreter: No such
file or directory
I've tried looking for the directory /opt/anaconda1anaconda2anaconda3/bin/python: but it simply doesn't exist.
Furthermore, when I run python from the terminal it runs as normal with the following displayed at the top
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
for completeness my .bashrc file resembles:
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u#\h \W]\$ '
# added by Anaconda3 4.0.0 installer
export PATH="/home/lukasz/anaconda3/bin:$PATH"
# python startup for up keys
export PYTHONSTARTUP=$HOME/.pythonstartup
I've tried following this and making the the appropriate changes but nothing, I've also attempted to do this but there really isn't a solution posted.
I would like to try to fix this without having to remove Anaconda and reinstalling it.
Something must have gone wrong during the installation, I suppose.
The bad interpreter means that a script is looking for an interpreter that doesn't exist - as you rightfully pointed out.
The problem is likely to be in the shebang #! statement of your conda script.
From Wikipedia: Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest
of the script's initial line as an interpreter directive; the
specified interpreter program is run instead, passing to it as an
argument the path that was initially used when attempting to run the
script.
If you run
cat ~/anaconda3/bin/conda
You will probably get the following:
#!/opt/anaconda1anaconda2anaconda3/bin/python
if __name__ == '__main__':
import sys
import conda.cli
sys.exit(conda.cli.main())
Changing the first line to point a correct interpreter, i.e., changing it to:
#!/home/lukasz/anaconda3/bin/python
Should make the conda command work.
If you are sure that you installed everything properly, then I'd suggest maybe reaching out for support from the anaconda community.
I encountered the same error while trying
conda
The error you should interpret as follows:
bash: "path_to_file_with_error": "path_to_file_it_points_to":
bad interpreter: No such file or directory
How to fix
Type in terminal
nano "path_to_file_with_error"
Change first line of the file to correct path of the python (in my case it was in miniconda/bin)
As the response above, this issue can be solved by changing the
#!/opt/anaconda1anaconda2anaconda3/bin/python
to
#!/opt/anaconda3/bin/python
However, as soon as you do the next installation, e.g. "conda install [...]" this will be changed again to anaconda1anaconda2anaconda3, for whatever reasons.
You might also realize some installation warnings and errors which are very likely to be related to this problem. If you want to get rid of this problem, you have to solve this warnings and errors. My strongest assumption is that there are missing administrator rights causing this problem, when you attempt to installs some conda packages the first time.
When you change the path to the interpreter conda will not be activated, so by following any of the previous answers you will end up in dead end.
you get the following
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
So to solve this renaming path issue you need to:
you can use any text editor:
nano ~/anaconda3/etc/profile.d/conda.sh
change the CONDA_EXE and CONDA_PYTHON_EXE paths to the correct path
example:
export
CONDA_EXE='/home/yourusername/anaconda3/bin/conda'
export _CE_M=''
export _CE_CONDA=''
export CONDA_PYTHON_EXE='/home/yourusername/anaconda3/bin/python'
then last step do:
source ~/anaconda3/etc/profile.d/conda.sh
To test your conda
Try:
conda activate
conda deactivate
to make this change permanent to all terminals
please add this line to ~/.bashrc
source ~/anaconda3/etc/profile.d/conda.sh
If somebody runs into this problem and none of the above solutions works, it could be that on some update process the conda executable (which is a python script) was replaced with an identical-looking script with one key difference, it contains windows line endings.
This results in that executing the script via bash e.g.:
<some_path>/conda/bin/conda
will result in the error, but executing directly via python works
<some_path>/conda/bin/python <some_path>/conda/bin/conda
Can be fixed by dos2unix
dos2unix <some_path>/conda/bin/conda
or just move the file away and move it back.
For centos/Rocky Linux 8 OS:
conda is a 32 bit application but centos OS is 64 bit,
you need to install package below:
yum install glibc.i686
reference:
https://forums.centos.org/viewtopic.php?t=14169
This question already has answers here:
"python" not recognized as a command
(14 answers)
Closed 2 years ago.
So I have recently installed Python Version 2.7.5 and I have made a little loop thing with it but the problem is, when I go to cmd and type python testloop.py I get the error:
'python' is not recognized as an internal or external command
I have tried setting the path but no avail.
Here is my path:
C:\Program Files\Python27
As you can see, this is where my Python is installed. I don't know what else to do. Can someone help?
Try "py" instead of "python" from command line:
C:\Users\Cpsa>py
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
I have found the answer... click on the installer and check the box "Add python to environment variables" DO NOT uninstall the old one rather click on modify....Click on link for picture...
You need to add that folder to your Windows Path:
https://docs.python.org/2/using/windows.html Taken from this question.
If you want to see python version then you should use py -V instead of python -V
C:\Users\ghasan>py -V
Python 3.7.1
If you want to go to python's running environment then you should use py instead of python
C:\Users\ghasan>py
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Here you can run the python program as:
print('Hello Python')
Hello Python
Firstly, be sure where your python directory. It is normally in C:\Python27. If yours is different then change it from the below command.
If after you install it python still isn’t recognized, then in PowerShell enter this:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27",
"User")
Close PowerShell and then start it again to make sure Python now runs. If it doesn’t,
restart may be required.
Type py -v instead of python -v in command prompt
i solved this by running CMD in administration mode, so try this.
Open CMD with administrative access(Right click then run as administrator) then type the following command there:
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
Replace My_python_lib with the folder name of your installed python like for me it was C:\python27.
Then to check if the path variable is set, type echo %PATH% you'll see your python part in the end. Hence now python is accessible.
From this tutorial
I have installed python 3.7.4. First, I tried python in my command prompt. It was saying that 'Python is not recognized command......'. Then I tried 'py' command and it works.
My sample command is:
py hacker.py
I have met same issue when I install Python, and it is resolved when I set a PATH in system, here are the steps.
Navigate to "Control Panel" -> "System"
Click "Advanced system settings" on the left
Click "Environment Variables"
Search and click "Path" variable
Click "Edit"
Add "C:\"to the environment variables field, if you are using Windows7, then separate it by a semicolon from the existing entry. If you are using Windows10, just simply click "New" to add.
Reopen the Command Prompt and try
enter image description here
From the Python docs, set the PATH like you did as above.
You should arrange for Python’s installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python27. Otherwise you will be reduced to a search of your whole disk
Use Tools ‣ Find or hit the Search button and look for “python.exe”. Supposing you discover that Python is installed in the C:\Python27 directory (the default at the time of writing), you should make sure that entering the command
Then execute the Python command using the full path name to make sure that works.
Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.
If you uninstalled then re-installed, and running 'python' in CLI, make sure to open a new CMD after your installation for 'python' to be recognized. 'py' will probably be recognized with an old CLI because its not tied to any version.
Option 1 : Select on add environment var during installation
Option 2 : Go to C:\Users-> AppData (hidden file) -> Local\Programs\Python\Python38-32(depends on version installed)\Scripts
Copy path and add to env vars path.
For me this path worked : C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts
It was a bit more confusing with the Python instructions once SQL Server 2019 was installed with Python. The actual path I find is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
Scripts run with an Execute command:
Declare #script nvarchar(max)=N'print(11-2)' execute sp_execute_external_script #language = N'Python', #script = #script
There is additional documentation in reference to SQL 2019's version of Python. There is a statement that recommends PIP be used only from a download of sqlmutils-x.x.x.zip located on git (https://www.github.com/Microsoft/sqlmutils) But there is a caveat. Currently this only works for R and not for Python (Anaconda and consequently pip). Python over SQL works but pip is not yet available. (11/25/2019)
Would be great to get an update when this occurs.
This question already has answers here:
"python" not recognized as a command
(14 answers)
Closed 2 years ago.
So I have recently installed Python Version 2.7.5 and I have made a little loop thing with it but the problem is, when I go to cmd and type python testloop.py I get the error:
'python' is not recognized as an internal or external command
I have tried setting the path but no avail.
Here is my path:
C:\Program Files\Python27
As you can see, this is where my Python is installed. I don't know what else to do. Can someone help?
Try "py" instead of "python" from command line:
C:\Users\Cpsa>py
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
I have found the answer... click on the installer and check the box "Add python to environment variables" DO NOT uninstall the old one rather click on modify....Click on link for picture...
You need to add that folder to your Windows Path:
https://docs.python.org/2/using/windows.html Taken from this question.
If you want to see python version then you should use py -V instead of python -V
C:\Users\ghasan>py -V
Python 3.7.1
If you want to go to python's running environment then you should use py instead of python
C:\Users\ghasan>py
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Here you can run the python program as:
print('Hello Python')
Hello Python
Firstly, be sure where your python directory. It is normally in C:\Python27. If yours is different then change it from the below command.
If after you install it python still isn’t recognized, then in PowerShell enter this:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27",
"User")
Close PowerShell and then start it again to make sure Python now runs. If it doesn’t,
restart may be required.
Type py -v instead of python -v in command prompt
i solved this by running CMD in administration mode, so try this.
Open CMD with administrative access(Right click then run as administrator) then type the following command there:
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
Replace My_python_lib with the folder name of your installed python like for me it was C:\python27.
Then to check if the path variable is set, type echo %PATH% you'll see your python part in the end. Hence now python is accessible.
From this tutorial
I have installed python 3.7.4. First, I tried python in my command prompt. It was saying that 'Python is not recognized command......'. Then I tried 'py' command and it works.
My sample command is:
py hacker.py
I have met same issue when I install Python, and it is resolved when I set a PATH in system, here are the steps.
Navigate to "Control Panel" -> "System"
Click "Advanced system settings" on the left
Click "Environment Variables"
Search and click "Path" variable
Click "Edit"
Add "C:\"to the environment variables field, if you are using Windows7, then separate it by a semicolon from the existing entry. If you are using Windows10, just simply click "New" to add.
Reopen the Command Prompt and try
enter image description here
From the Python docs, set the PATH like you did as above.
You should arrange for Python’s installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python27. Otherwise you will be reduced to a search of your whole disk
Use Tools ‣ Find or hit the Search button and look for “python.exe”. Supposing you discover that Python is installed in the C:\Python27 directory (the default at the time of writing), you should make sure that entering the command
Then execute the Python command using the full path name to make sure that works.
Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.
If you uninstalled then re-installed, and running 'python' in CLI, make sure to open a new CMD after your installation for 'python' to be recognized. 'py' will probably be recognized with an old CLI because its not tied to any version.
Option 1 : Select on add environment var during installation
Option 2 : Go to C:\Users-> AppData (hidden file) -> Local\Programs\Python\Python38-32(depends on version installed)\Scripts
Copy path and add to env vars path.
For me this path worked : C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts
It was a bit more confusing with the Python instructions once SQL Server 2019 was installed with Python. The actual path I find is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
Scripts run with an Execute command:
Declare #script nvarchar(max)=N'print(11-2)' execute sp_execute_external_script #language = N'Python', #script = #script
There is additional documentation in reference to SQL 2019's version of Python. There is a statement that recommends PIP be used only from a download of sqlmutils-x.x.x.zip located on git (https://www.github.com/Microsoft/sqlmutils) But there is a caveat. Currently this only works for R and not for Python (Anaconda and consequently pip). Python over SQL works but pip is not yet available. (11/25/2019)
Would be great to get an update when this occurs.
When I type python into the command line, the command prompt says python is not recognized as an internal or external command, operable program, or batch file. What should I do?
Note: I have Python 2.7 and Python 3.2 installed on my computer.
I have installed the latest Python for Win10 from Releases for Windows.
Just typing py in the Command Prompt Window starts Python.
Microsoft Windows [Version 10.0.15048]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\sg7>py
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>`enter code here`
Testing:
>>> print("hello!")
hello!
>>>
Please be aware that in my case Python was installed in C:\Users\sg7\AppData\Local\Programs\Python\Python36> directory
C:\Users\sg7\AppData\Local\Programs\Python\Python36>dir
Volume in drive C is Windows7_OS
Volume Serial Number is 1226-12D1
Directory of C:\Users\sg7\AppData\Local\Programs\Python\Python36
08/05/2018 07:38 AM <DIR> .
08/05/2018 07:38 AM <DIR> ..
12/18/2017 09:12 AM <DIR> DLLs
12/18/2017 09:12 AM <DIR> Doc
12/18/2017 09:12 AM <DIR> include
12/18/2017 09:12 AM <DIR> Lib
12/18/2017 09:12 AM <DIR> libs
10/03/2017 07:17 PM 30,334 LICENSE.txt
10/03/2017 07:17 PM 362,094 NEWS.txt
10/03/2017 07:15 PM 100,504 python.exe
10/03/2017 07:12 PM 58,520 python3.dll
10/03/2017 07:12 PM 3,610,776 python36.dll
10/03/2017 07:15 PM 98,968 pythonw.exe
08/05/2018 07:38 AM 196,096 Removescons.exe
08/05/2018 07:38 AM 26,563 scons-wininst.log
08/05/2018 07:38 AM <DIR> Scripts
12/18/2017 09:12 AM <DIR> tcl
12/18/2017 09:12 AM <DIR> Tools
06/09/2016 11:53 PM 87,888 vcruntime140.dll
9 File(s) 4,571,743 bytes
10 Dir(s) 20,228,898,816 bytes free
When I am at C:\Users\sg7> directory level python can be invoked by typing
AppData\Local\Programs\Python\Python36\python
C:\Users\samg>AppData\Local\Programs\Python\Python36\python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Newer Python 3.7 will be installed at:
C:\Users\YourUserNameHere\AppData\Local\Programs\Python\Python37
If you wish you can add to your path environment variable:
%USERPROFILE%\AppData\Local\Programs\Python\Python36
It finally worked!!!
I needed to do things to get it to work
Add C:\Python27\ to the end of the PATH system variable
Add C:\Python27\ to the end of the PYTHONPATH system variable
I had to add these to both for it to work.
If I added any subdirectories, it did not work for some reason.
Thank you all for your responses.
The video was very useful.
Go to system properties -> Advance ( or type "system env" in
start menu.)
Click environment variables
Edit the 'PATH' variable
Add 2 new paths 'C:\Python27' and 'C:\Python27\scripts'
Run cmd again and type python.
it worked for me
Rather than the command "python", consider launching Python via the py launcher, as described in sg7's answer, which runs your latest version of Python (or lets you select a specific version). The py launcher is enabled via a check box during installation (default: "on").
Nevertheless, you can still put the "python" command in your PATH, either at "first installation" or by "modifying" an existing installation.
First Installation:
Checking the "[x] Add Python x.y to PATH" box on the very first dialog. Here's how it looks in version 3.8:
This has the effect of adding the following to the PATH variable:
C:\Users\...\AppData\Local\Programs\Python\Python38-32\Scripts\
C:\Users\...\AppData\Local\Programs\Python\Python38-32\
Modifying an Existing Installation:
Re-run your installer (e.g. in Downloads, python-3.8.4.exe) and Select "Modify".
Check all the optional features you want (likely no changes), then click [Next]. Check [x] "Add Python to environment variables", and [Install].
In Windows 7 python start command in command prompt is
c:\>python3
but in Windows 10 python start command in command prompt is
C:\>py
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\>py --version
Python 3.6.3
C:\>
But in Windows 10 python3 syntax not work also not given any error.
Django start command also uses py instead of python3.
d:\>py manage.py runserver
In case someone else has the same issue, if you have already added to PATH and it (C:\Users\pete.kirkham\AppData\Local\Programs\Python\Python39\python) works if you run with a full path, on Win 10 the command line command python is by default aliased to the Windows store.
Go to settings > App execution aliases and disable the alias for python that runs App installer instead.
More details can be found in this question CMD opens window store when I type python
(presumably if your organisation doesn't disable the Windows Store and you install via the Store it disables this when you install, but installing via download from python.org does not)
This working for me :
PS C:\Users\MyUsername> py -V
Python 3.9.0
They gave us a script to do this for us already
C:\Users\hUTBER\AppData\Local\Programs\Python\tools\scripts\win_add2path.py
You'll need to make sure that you close and open the cmd otherwise it won't have the new path there.
If you can't find this script these are the paths that it will add and I had to add manually in the end.
C:\Users\hUTBER\AppData\Local\Programs\Python\Python35
C:\Users\hUTBER\AppData\Local\Programs\Python\Python35\Scripts
Where mine and now python works in the cmd
Python 3.10 uses py and not python.
Try py --version if you are using this version.
Even after following the instructions from the valuable answers above, calling python from the command line would open the Microsoft Store and redirect me to a page to download the software.
I discovered this was caused by a 0 Ko python.exe file in AppData\Local\Microsoft\WindowsApps which was taking precedence over my python executable in my PATH.
Removing this folder from my PATH solved it.
Kalle posted a link to a page that has this video on it, but it's done on XP. If you use Windows 7:
Press the windows key.
Type "system env". Press enter.
Press alt + n
Press alt + e
Press right, and then ; (that's a semicolon)
Without adding a space, type this at the end: C:\Python27
Hit enter twice. Hit esc.
Use windows key + r to bring up the run dialog. Type in python and press enter.
Just a few comments:
Don't set PYTHONPATH if all you want is to get Python on the PATH. The PYTHONPATH environment variable tells Python where to look for modules to import. Setting it to C:\Python27\ will not accomplish anything useful, although it's probably harmless.
Modifying environment variables (including PATH) from the "Edit System Variables" has no effect on already running processes. This means you have to re-launch cmd.exe for the changes to work. A reboot, however, is not required.
When modifying the PATH, also add the Scripts subdirectory. Or, to put it in other words (and using the previous example): add ;C:\Python27;C:\Python27\Scripts. This will allow you to run scripts like easy_install, pip, virtualenv or sphinx from the command line - once you install those, that is. This is about as UNIX-y as it gets for Windows. (N.B. The Scripts subdirectory is not present after a clean install of Python, but will be created when needed.)
Don't put any additional Lib or DLL directory on the PATH. There's no need, and it might do harm.
If you have installed multiple versions of Python (which isn't all that uncommon) you might be better off not putting any of them on the PATH but instead create different shortcuts to cmd.exe for the different versions which set the PATH for each version. You might also be interested in PEP-397.
I am probably the most novice user here, I have spent six hours just to run python in the command line in Windows 8. Once I installed the 64-bit version, then I uninstalled it and replaced it with 32-bit version. Then, I tried most suggestions here, especially by defining path in the system variables, but still it didn't work.
Then I realised when I typed in the command line:
echo %path%
The path still was not directed to C:\python27. So I simply restarted the computer, and now it works.
You have to add the python executable in your SYSTEM PATH, do the following, My Computer > Properties > Advanced System Settings > Environment Variables > Then under system variables I create a new Variable called "PythonPath". In this variable I have "C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-foolder-on-the-path".
Here's one for for office workers using a computer shared by others.
I did put my user path in path and created the PYTHONPATH variables in my computer's PATH variable. Its listed under Environment Variables in Computer Properties -> Advanced Settings in Windows 7.
Example:
C:\Users\randuser\AppData\Local\Programs\Python\Python37
This made it so I could use the command prompt.
Hope this helped.
Seems like the python executable is not found in your PATH, which defines where it is looking for executables. See the official instructions for instructions on how to get the python executables in your PATH.
Add the python bin directory to your computer's PATH variable. Its listed under Environment Variables in Computer Properties -> Advanced Settings in Windows 7. It should be the same for Windows 8.
You need to add python to your PATH. I could be wrong, but Windows 7 should have the same cmd as Windows 8. Try this in the command line. Using setx permanently makes changes to you PATH. Note there are no equal signs, and quotes are used.
setx PATH "%PYTHONPATH%;C:\python27"
Set the c:\python27 to the directory of the python version you'd like to run from the typing python into the command prompt.
Just go with the command py. I'm running python 3.6.2 on windows 7 and it works just fine.
I removed all the python paths from the system directory and the paths don't show up when I run the command echo %path% in cmd. Python is still working fine.
I ran into this by accidentally pressing enter while typing python...
EDIT: I didn't mention that I installed python to a custom folder C:\Python\
When you add the python directory to the path (Computer > Properties > Advanced System Settings > Advanced > Environmental Variables > System Variables > Path > Edit), remember to add a semicolon, then make sure that you are adding the precise directory where the file "python.exe" is stored (e.g. C:\Python\Python27 if that is where "python.exe" is stored). Then restart the command prompt.
If you are working with command prompt and if you are facing the issue even after adding python path to system variable PATH.
Remember to restart the command prompt (cmde.exe).
I wanted to add a common problem that happens on installation. It is possible that the path installation length is too long. To avoid this change the standard path so that it is shorter than 250 characters.
I realized this when I installed the software and did a custom installation, on a WIN10 operation system. In the custom install, it should be possible to have Python added as PATH variable by the software
In my scenario, when I execute py -V it will show me the python version,
but python -V will show me Python was not found;
Answers above show us that we may need to set environment variable for python. But I already set the environment variable.
Finally, when I try to execute where.exe python command, it showed me with 2 python.exe, one of them is in path \AppData\Local\Microsoft\WindowsApps which is also set as environment, so I delete this python.exe file, then it worked.
None of these actually worked for me.
What you needed to do to really have Python recognized within it's path, is to download the latest version of it only from this website and not other website:
https://www.python.org/downloads/
But be careful while installing; the default installation is set not to add Python's path to the Environmental Variables in the Control Panel if you have a Windows computer, but you should change the setting so that the installation does it, and it will all be done by itself.