Can I find the path to an executable executing a python script from a python script?

Is there a way to get the path to an executable that runs the current python script (from within the python script)?

+7
python introspection
source share
1 answer

That should do what you want.

>>> import sys >>> sys.executable 'C:\\Python26\\python.exe' >>> import os >>> os.path.dirname(sys.executable) 'C:\\Python26' 
+8
source share

All Articles