Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the python.exe location programmatically? [duplicate]

Tags:

python

People also ask

How do I find the path of a Python executable?

Press Start in the lower left corner of your display; press Search; in the search window, press all files and folders; in the top textline that appears, type python.exe; press the Search button. After several minutes, the folder where Python is installed will be listed --- that folder name is the path to Python.

How do I check my PyInstaller path?

To determine application path in a Python EXE generated by pyInstaller, we can check the sys. frozen property. If the value is True , then the script code is running in the exe file.

Where is Python executable Linux?

1 Answer. For finding the full path of the Python interpreter you can use sys. executable which contains the full path of the currently running Python interpreter.


This works in Linux & Windows:

Python 3.x

>>> import sys
>>> print(sys.executable)
C:\path\to\python.exe

Python 2.x

>>> import sys
>>> print sys.executable
/usr/bin/python

sys.executable is not reliable if working in an embedded python environment. My suggestions is to deduce it from

import os
os.__file__

I think it depends on how you installed python. Note that you can have multiple installs of python, I do on my machine. However, if you install via an msi of a version of python 2.2 or above, I believe it creates a registry key like so:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe

which gives this value on my machine:

C:\Python25\Python.exe

You just read the registry key to get the location.

However, you can install python via an xcopy like model that you can have in an arbitrary place, and you just have to know where it is installed.