I have two versions of python installed on my computer. 3.2 64 bit installed in C:\Python32\ and 2.7 32 bit installed in C:\Python27.
I also have a C# application digging in the registry (64 and 32 bit) to get the install path of the most appropriate python version to use depending on various conditions.
I have a script called Code.py, which is run by the C# application using the python version it selected.
In the Code.py script, I want to run another script located in either C:\Python32\Scripts or C:\Python27\Scripts, depending on which python version was used. However, I want to know what is the install path of that python.exe file used to run the script I am currently in. Is there a way to do that or I'll have to communicate the install path selected by the C# application as an argument when I run the script (which I would want to avoid)?
Edit: I call the script inside my script as an external script using this code
p = subprocess.Popen(["python", installPath + "\\Scripts\\Flake8", file], stdout=subprocess.PIPE)
Use sys.executable
.
>>> import sys
>>> sys.executable
'/usr/bin/python'
os.path.split()
removes the last component for you if all you need is the path:
>>> import os.path
>>> os.path.split(sys.executable)
('/usr/bin', 'python')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With