Get python executable full path from C++
<p>I have a program, written in C++. I would like to get full path to python executable from it. For example, if I open Windows command prompt (cmd.exe) and type python, it use python executable from <code>PATH</code>. So, i would like to have a function <code>get_exec_path("python")</code> whick returns something like <code>C:\Python27\python.exe</code>. <code>C:\Python27\</code> is in my <code>PATH</code>.
I need this for calling python scripts from C++ code. Embedding python in C++ is a bad idea for my purposes. I used to call it like this:</p>

<pre><code>std::system("start \"\" /WAIT python myscript.py --arg1 arg1 --arg2 arg2")
</code></pre>

<p>but this method shows command prompt window, I would like some kind of background work. For this purpose I used <code>CreateProcess</code> with second argument <code>"C:\Python27\python.exe myscript.py --arg1 arg1 --arg2 arg2"</code>. So, I need full path to python executable from <code>PATH</code> variable.</p>

<p>There are some solutions, that could help you.</p>

<ul>
<li><p>Get from windows registry using C++ tools. Replace {ver} with actual version. "3.5" was in my case.</p>

<p>HKCU\SOFTWARE\Python\PythonCore\{ver}\InstallPath\ExecutablePath</p></li>
<li><p>Use where.exe utility to perform PATH search. It works like linux "which".</p>

<p>C:\Users\admin>where python<br>
C:\Users\admin\AppData\Local\Programs\Python\Python35\python.exe</p></li>
</ul>

python c++