Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I find the path of the executable running a python script from within the python script?

Is there a way to retreive the path of the executable that is running the current python script (from within the python script)?

like image 889
Daniel Fortunov Avatar asked Apr 22 '10 14:04

Daniel Fortunov


1 Answers

That should do what you want

>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'

>>> import os
>>> os.path.dirname(sys.executable)
'C:\\Python26'
like image 145
luc Avatar answered Sep 30 '22 03:09

luc