Friday, May 17, 2024

How do you launch Python assuming it is installed?

Python from python.org and many other software programs installs python and they may choose to install in different folders or locations. Finding where it is installed is important. If you need to run python on a command prompt, the python executable should be in the environment's path. You may note that you may have multiple versions of Python installed on your computer for varying requirements. You should know what version is installed and where.

In this post you will get to know ways and means to find the python executable on your computer.

1. This is the easiest. You try to check for Python using your command prompt as shown. If you get the following reply:

This only means the python.exe is not in the path C:\

============================================

C:\>python -c Print 'Hello'

Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.

============================================

If you find a python in the directory, it may be a short cut, if a file existed.

If I run without arguments as shown above, I am taken to the Windows Store to download Python 3.12 as shown.


I already have Python 3.12 installed when I installed PyCharm. 

You can check if the executable python is in the environment's path as shown:

========================

C:\Users\hoden>path

PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\hoden\AppData\Local\Programs\Python\Launcher\;C:\Users\hoden\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.3\bin;

========================

The executable is in the JetBrains directory that was installed for PyCharm as shown.

2. There is another way to find where python is installed.


Run the following command at command prompt:

======================================

C:\>where python

C:\Users\hoden\AppData\Local\Microsoft\WindowsApps\python

C:\Users\hoden\AppData\Local\Microsoft\WindowsApps\python.exe

========================================

In this folder,

C:\Users\hoden\AppData\Local\Microsoft\WindowsApps

You find two other python executables as well, python and python3. These are in the environment's PATH as well.

Here is the properties pages of one of them,


As you can see this is an empty file. There are several reasons why this file exists here. It is more like a placeholder or a shortcut for a non existent file and sometimes open a link in the web browser for a download location (Windows Store) as we saw earlier.

3. This yet another way. Windows Powershell is a powerful program that can also be used.There are two ways of starting Powershell, as a command line program or an interactive way.

You could also use Windows Powershell as shown:

===============================

PS C:\Users\hoden> Get-Command python


CommandType     Name                                               Version    Source                                                             

-----------     ----                                               -------    ------                                                             

Application     python.exe                                         0.0.0.0    C:\Users\hoden\AppData\Local\Microsoft\WindowsApps\python.exe  

===================================================

This is similar what we saw earlier. It showed the same file we saw earlier.

3. The following is not run in PowerShell but on the C:\ prompt.

However, if you have multiple versions of python installed you can try this:

==========================================

C:\Windows\System32>py -0

 -V:3.12 *        Python 3.12 (64-bit)

===========================================

This does not show the path but flags the version. if you want both path and version try this:

================================

C:\Users\hoden>py --list-paths

 -V:3.12 *        C:\Users\hoden\AppData\Local\Programs\Python\Python312\python.exe

================================

You can check this here:

=============

 Directory of C:\Users\hoden\AppData\Local\Programs\Python\Python312


05/05/2024  05:33 PM    <DIR>          .

05/05/2024  05:32 PM    <DIR>          ..

05/05/2024  05:32 PM    <DIR>          DLLs

05/05/2024  05:32 PM    <DIR>          Doc

05/05/2024  05:32 PM    <DIR>          include

05/05/2024  05:32 PM    <DIR>          Lib

05/05/2024  05:32 PM    <DIR>          libs

10/02/2023  01:27 PM            36,874 LICENSE.txt

10/02/2023  01:28 PM         1,664,545 NEWS.txt

10/02/2023  01:27 PM           103,192 python.exe

10/02/2023  01:27 PM            68,376 python3.dll

10/02/2023  01:27 PM         6,972,184 python312.dll

10/02/2023  01:27 PM           101,656 pythonw.exe

05/05/2024  05:33 PM    <DIR>          Scripts

05/05/2024  05:32 PM    <DIR>          tcl

10/02/2023  01:27 PM           109,392 vcruntime140.dll

10/02/2023  01:27 PM            49,520 vcruntime140_1.dll

               8 File(s)      9,105,739 bytes

               9 Dir(s)  102,834,245,632 bytes free

===================================================================

There is also a executable pythonw.exe in the above folder. It will give no response should you click on it. It is supposed to work with a python GUI. If you need to use this you will have to use the other system files in the System.IO.

Finally, when we installed PyCharm from the JetBrains site, we created this directory. We also chose to include this in the PATH as shown.

C:\Program Files\JetBrains\PyCharm Community Edition 2023.3.3\bin;

What do we have in this directory?
The BIN folder has two Applications pycharm64 and jetbrains_client64. The jetbrains_client64.exe connects you to an external server if there is one installed. It is a thin client.

However, clicking python64.exe in the installation folder opens up the GUI of PyCharm as shown.


We will be using this for exploring the image recognition programs. Also, JetBrains created a shortcut for this executable on the desktop.




No comments: