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
- I run the code on python just typing
Q60471933.py
from datetime import datetime
now = datetime.now()
dt = now.strftime("%H:%M:%S")
print("Hello World", dt)
# Q60471933.py
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
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
:
Have you tried "python" instead of "python3"?
– Daniel Reis
Priscila, how did you install Python on Windows? You remembered to insert the path of the executable into the environment variable
PATH
?– Woss
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)
– Augusto Vasques