Daniel Fortunov
Daniel Fortunov

Reputation: 44323

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)?

Upvotes: 8

Views: 378

Answers (1)

luc
luc

Reputation: 43096

That should do what you want

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

>>> import os
>>> os.path.dirname(sys.executable)
'C:\\Python26'

Upvotes: 7

Related Questions