Install Python 3 for windows running from the command line

Just curious, is there any special reason why Python 3.x is not installed on Windows to run by default with the command line "python3", as it does on Mac OSX and Linux? Is there a way to configure Python to work like this? Thank you

EDIT: just to add, the reason I'm asking for is that I have both Python 2 and 3 interpreters installed on my computer, and therefore this is ambiguous, since both of them are run using the python command.

+6
source share
4 answers

the reason I'm asking about is that Python 2 and 3 are also installed on my computer, and therefore it is ambiguous, since both are executed using the python command.

To run the Python 2 executable:

C:\> py -2 

To run the Python 3 executable:

 C:\> py -3 

where py is a Python launcher that is associated with your Python 3 installation.

py recognizes that shebang (for example, #!/usr/bin/env python3 runs the Python 3 executable), it respects virtualenv (if you run py without specifying an explicit python executable), i.e. do:

 C:\> py your_script.py 

and the correct version of python is used automatically - you do not need to explicitly specify the version of Python on the command line.

Is there any special reason why Python 3.x is not installed on Windows to run by default with the "python3" command line, as it does on Mac OSX and Linux?

OSX and Linux have the python executable installed by default, as a rule, and in most cases it refers to the Python 2 version, so you need to have a separate python3 name.

By default, there is no Python on Windows. And so any version you installed is just python (I think). The recommended way to manage multiple versions of python is to use the Python launcher.

Is there a way to configure Python to work like this?

If you want to type python3 some_script.py instead of py some_script.py or even just some_script (it is assumed that .py is in %PATHEXT% and the Python launcher is configured to run Python scripts (check out assoc .py and ftype Python.File ) - by default), then create a bat file, for example, python3.cmd and put it in %PATH% :

 "C:\path to\Python 3.X\python.exe" %* 
+10
source

You must add the python bin folder to your path. You can do it manually, but when you install python, I remember that you have the opportunity to do it.

+1
source

You probably missed the checkbox at the bottom of the installer.

Full documentation here: https://docs.python.org/3/using/windows.html

Then, I think you just ran python , not python3 from the command line. The reason Unix systems have python3 is because python is used by default for Python2.x on many systems.

Install window

0
source

I work with several Python 2.x and 3.x distributions on Windows. Some of them are โ€œportable,โ€ that is, they are not written to the Windows registry and therefore are not available with the py.exe version py.exe that ships with Python 3.3+. To maintain reasonableness, I wrote SelectPython.bat , which is available on the bitpack . It configures the PYTHONHOME , PYTHONPATH and PATH variables according to your purpose (relative or absolute path to the parent directory python.exe ). You can do this in such a way that it remains private for the rest of the command line session:

 > SelectPython C:\Path\To\Desired\Version\Of\Python > python 

or temporarily, that is, invoke a specific python command without affecting the shell environment from which you are invoking it:

 > SelectPython C:\Path\To\Desired\Version\Of\Python python -c "import sys;print(sys.version)" 

You may find this helpful.

0
source

All Articles