Run script with Python: command "python3" is not recognized

Asked

Viewed 2,879 times

1

Good afternoon,

I’m learning to create programs in python language and run them..

I am using Windows, but when opening the Prompt comado and type python3 somador.py the message it generates is:

"python3" is not recognised as an internal or external command, a operable program or a batch file.

What I do?

  • 5

    Have you tried "python" instead of "python3"?

  • 8

    Priscila, how did you install Python on Windows? You remembered to insert the path of the executable into the environment variable PATH?

  • Pricila stop suffering from building, checking dependency issues, environment incompatibility, downloading crazy distributions, ... just remove old python installations and install the Anaconda,I was about to give up Python and they taught me that these days. (PS: I have nothing to do with the company)

3 answers

8

  • Update:

1) Download an official version of Python

2) Use custom installation by following the screen clippings below.

3) Perform your somador.py direct on the command line just by typing the name somador.py

  • Cutout of canvas #1

enter image description here

  • Cutout of canvas #2

enter image description here

  • Cutout of canvas #3

enter image description here


  • I run the code on just typing Q60471933.py
from datetime import datetime
now = datetime.now()
dt = now.strftime("%H:%M:%S")
print("Hello World", dt) 
# Q60471933.py

  • Outputs:

enter image description here



Previous post


To use your script/program somador.py I suggest we check the possible executable names/paths:

To check the path(s) and the name(s) (s), open the cmd.exe and type:


%__APPDIR__%where.exe /r \ python*.exe

In my Windows this command returns a list with all names and paths:


C:\Program Files (x86)\IntelSWTools\debugger_2018\python\intel64\python.exe
C:\Program Files (x86)\IntelSWTools\debugger_2018\python\intel64\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython2\python.exe
C:\Program Files (x86)\IntelSWTools\intelpython2\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython2\pkgs\python-2.7.16-10\python.exe
C:\Program Files (x86)\IntelSWTools\intelpython2\pkgs\python-2.7.16-10\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython3\python.exe
C:\Program Files (x86)\IntelSWTools\intelpython3\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython3\pkgs\python-3.6.9-4\python.exe
C:\Program Files (x86)\IntelSWTools\intelpython3\pkgs\python-3.6.9-4\pythonw.exe
C:\Program Files (x86)\IntelSWTools\parallel_studio_xe_2018\debugger_2018\python\intel64\python.exe
C:\Program Files (x86)\IntelSWTools\parallel_studio_xe_2018\debugger_2018\python\intel64\pythonw.exe
C:\Program Files (x86)\IntelSWTools\parallel_studio_xe_2018.4.062\debugger_2018\python\intel64\python.exe
C:\Program Files (x86)\IntelSWTools\parallel_studio_xe_2018.4.062\debugger_2018\python\intel64\pythonw.exe
C:\Program Files (x86)\IntelSWTools\VTune Amplifier\vpp\server\dist\3rdparty\vpp-python\python.exe
C:\Program Files (x86)\IntelSWTools\VTune Amplifier\vpp\server\dist\3rdparty\vpp-python\pythonw.exe
C:\Program Files (x86)\IntelSWTools\VTune Amplifier 2019\vpp\server\dist\3rdparty\vpp-python\python.exe
C:\Program Files (x86)\IntelSWTools\VTune Amplifier 2019\vpp\server\dist\3rdparty\vpp-python\pythonw.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\python.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pythonw.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Lib\site-packages\pythonwin\Pythonwin.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Lib\site-packages\win32\pythonservice.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\python-3.6.5-h0c2934d_0\python.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\python-3.6.5-h0c2934d_0\pythonw.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\pywin32-223-py36hfa6e2cd_1\Lib\site-packages\pythonwin\Pythonwin.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\pywin32-223-py36hfa6e2cd_1\Lib\site-packages\win32\pythonservice.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\pythonw.exe
C:\ProgramData\Microsoft\VisualStudio\Packages\CPython3.Exe.x64,version=3.6.6,chip=x64\python-3.6.6-amd64.exe
C:\Python27\python.exe
C:\Python27\pythonw.exe
C:\Users\All Users\Microsoft\VisualStudio\Packages\CPython3.Exe.x64,version=3.6.6,chip=x64\python-3.6.6-amd64.exe
C:\Users\ecker\AppData\Local\KDevelop\python\python.exe
C:\Users\ecker\AppData\Local\KDevelop\python\pythonw.exe
C:\Users\ecker\AppData\Local\Package Cache\{0f40e78b-67e1-4e0c-a2fd-e9325d9dfc82}\python-3.7.2.exe
C:\Users\ecker\AppData\Local\Package Cache\{37ec7371-0827-49f1-be8a-63c158184b9c}\python-3.8.0.exe
C:\Users\ecker\AppData\Local\Package Cache\{a2e7eb2f-e31e-47eb-82ca-63b3854f5354}\python-3.6.6-amd64.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\python.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\pythonw_d.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\python_d.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\pythonwin\Pythonwin.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\win32\pythonservice.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\Lib\venv\scripts\nt\python.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\Lib\venv\scripts\nt\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python38-32\python.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python38-32\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python38-32\Lib\venv\scripts\nt\python.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python38-32\Lib\venv\scripts\nt\pythonw.exe
C:\Users\ecker\Downloads\python-3.7.2.exe
C:\Users\ecker\Downloads\python-3.8.0.exe
C:\Users\Todos os Usuários\Microsoft\VisualStudio\Packages\CPython3.Exe.x64,version=3.6.6,chip=x64\python-3.6.6-amd64.exe
C:\Windows\Installer\{9255D53C-6C21-4664-AAF3-6EAC50F867DA}\python_icon.exe 

  • To filter and get only the names:
python.exe, pytonw.exe, python2.exe python3.exe, python3-2.7.16-10, python-3.6.9-4.exe, python_etc...

  • Just change the * for ?: python*.exe for python?.exe, then we will summarize the output of the previous command and get:
%__APPDIR__%where.exe /r \ python?.exe

  • Returns a more short list:
C:\Program Files (x86)\IntelSWTools\debugger_2018\python\intel64\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython2\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython2\pkgs\python-2.7.16-10\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython3\pythonw.exe
C:\Program Files (x86)\IntelSWTools\intelpython3\pkgs\python-3.6.9-4\pythonw.exe
C:\Program Files (x86)\IntelSWTools\parallel_studio_xe_2018\debugger_2018\python\intel64\pythonw.exe
C:\Program Files (x86)\IntelSWTools\parallel_studio_xe_2018.4.062\debugger_2018\python\intel64\pythonw.exe
C:\Program Files (x86)\IntelSWTools\VTune Amplifier\vpp\server\dist\3rdparty\vpp-python\pythonw.exe
C:\Program Files (x86)\IntelSWTools\VTune Amplifier 2019\vpp\server\dist\3rdparty\vpp-python\pythonw.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pythonw.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\pkgs\python-3.6.5-h0c2934d_0\pythonw.exe
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\pythonw.exe
C:\Python27\pythonw.exe
C:\Users\ecker\AppData\Local\KDevelop\python\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python37-32\Lib\venv\scripts\nt\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python38-32\pythonw.exe
C:\Users\ecker\AppData\Local\Programs\Python\Python38-32\Lib\venv\scripts\nt\pythonw.exe

  • To search only the paths stored in the variable %path%, just replace:


    /r \ arquivo*.ext for "%path%:arquivo*.ext", getting:


%__APPDIR__%where.exe "%path%:python?.exe"

  • Returning me an even more short list:
C:\Python27\python.exe
C:\Python27\pythonw.exe

  • Python.exe -3 x Python.exe -2

  • Py.exe -3 x Py.exe -2


    • Without wanting to enter the theme, there is still the option to run your code in python 2* or in python 3, only using the flag -2 or -3.

What can also be done is to invoke/use the Py.exe, which will automatically select from among the installed versions (coming from python.org) on the computer, it takes the latest to execute your code


  • For more/more accurate information, see these links:

Recent Questions: How to Use Python

Python Py.exe Launcher for Windows/en


Note: 1) To use the command where.exe and search throughout the HD use:

%__APPDIR__%where.exe /r \ arquivo*.ext


%__APPDIR__%where.exe /r \ python*.exe

Note: 2) To use the command where.exe and search only in the variable %path% use:

where.exe "%path%:arquiv.ext"


%__APPDIR__%where.exe "%path%:python*.exe"

Only for path tests, versions, etc... test these commands:


"%windir%\py.exe" somador.py
"%windir%\py.exe" -2 somador.py
"%windir%\py.exe" -3 somador.py

  • What I also do for the purpose of checking/testing a system and checking which versions of Python are available is a hybrid bat (python + bat):
1>2# : ^
'''
@echo off && if exist %windir%\py.exe (
     for %%i in (" " -2 -3)do "%windir%\py.exe" %%~i "%~f0"|%__APPDIR__%find.exe /i "Current Time" 2>nul && (
     echo/ Executou Py.exe %%~i) || (echo/ Py.exe %%~i nao executado)) else (echo/ Py.exe nao encontrado^!! )
goto :EOF
'''
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)

  • The execution returns to me:
Current Time = 16:54:59
 Executou Py.exe 
('Current Time =', '16:54:59')
 Executou Py.exe -2
Current Time = 16:54:59
 Executou Py.exe -3

  • What returns from execution means:
 Executou Py.exe    tenho py.exe e tenho Python 

 Executou Py.exe -2 tenho py.exe e tenho Python 2 

 Executou Py.exe -3 tenho py.exe e tenho Python 3


How to use Python hybrid with bat/cmd


Consider the comment of @woss...

Add the python path/path to the variable Path:


Here’s a tutorial/En of how to add python to path

Optionally and not very recommended, use the command below concatenating the way to the drive:\pasta\do\python using the delimiter ;

%path% +delimiter+path_do_python

set "path=%path%;C:\Python27;C:\Python38;%PATH%"

Concatenate your python path using the delimiter ; : %path% +delimiter+path_do_python:


3

If you have already done the installation of Python3.x on your Windows find the directory in which it was installed and configure the PATH environment variable.

See how is the path variable of my Windows:
inserir a descrição da imagem aqui



After setting the PATH variable you will need to close and open the command prompt again.

If you don’t already have Python3.x installed go to the project website (https://www.python.org/downloads/release/python-381/) and download the latest stable version.

inserir a descrição da imagem aqui

  • More necessary than any vote up/down in the question, would be an answer to the question/problem potential for any beginner in the language, your answer meets solution where voting actions down have not solved, an action that is unique in the platform. Provide support/incentive/propose solution to beginners.

  • Congratulations on the exemplary participation/initiative!

-8

In Windows it is not necessary to say which version of Python, just type python and the file name with the extension .py.

In your case it would look like this:

python somador.py 

In Unix environments the Python version is required.

  • 8

    It’s wrong. When there are two versions of Python in Windows, you need to call them with python for 2.x and python3 for 3.x.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.