Hi all, I have a puzzle for you today. I am trying to get the ArcGIS Pro install folder from Python. I am open to suggestions on how to accomplish this task, but the following approach should work (and works for me with Desktop, although I usually use os.environ["AGSDESKTOPJAVA"] instead).
- I don't want to use arcpy.GetInstallInfo() because I want to find out where the install is before I take the time to import arcpy.
- We install in a non-standard location to avoid spaces in the path.
Here is my attempt:
D<SPAN class="punctuation token">:</SPAN>\Users\jwpowell<SPAN class="operator token">></SPAN>C<SPAN class="punctuation token">:</SPAN>\Python27\ArcGIS10<SPAN class="number token">.4</SPAN>\python<SPAN class="punctuation token">.</SPAN>exe
Python <SPAN class="number token">2.7</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="number token">10</SPAN> <SPAN class="punctuation token">(</SPAN>default<SPAN class="punctuation token">,</SPAN> May <SPAN class="number token">23</SPAN> <SPAN class="number token">2015</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">09</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">40</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">32</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">[</SPAN>MSC v<SPAN class="number token">.1500</SPAN> <SPAN class="number token">32</SPAN> bit <SPAN class="punctuation token">(</SPAN>Intel<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> on win32
Type <SPAN class="string token">"help"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"copyright"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"credits"</SPAN> <SPAN class="operator token">or</SPAN> <SPAN class="string token">"license"</SPAN> <SPAN class="keyword token">for</SPAN> more information<SPAN class="punctuation token">.</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">import</SPAN> _winreg
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">with</SPAN> _winreg<SPAN class="punctuation token">.</SPAN>OpenKey<SPAN class="punctuation token">(</SPAN>_winreg<SPAN class="punctuation token">.</SPAN>HKEY_LOCAL_MACHINE<SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> r<SPAN class="string token">"SOFTWARE\ESRI\ArcGISPro"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> key<SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> pro_path <SPAN class="operator token">=</SPAN> _winreg<SPAN class="punctuation token">.</SPAN>QueryValueEx<SPAN class="punctuation token">(</SPAN>key<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"InstallDir"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<stdin>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
WindowsError<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>Error <SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> The system cannot find the file specified<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
And yet, I can see this key with reg query fine:
D:\Users\jwpowell>reg query HKLM\SOFTWARE\ESRI\ArcGISPro /v InstallDir
HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\ArcGISPro
InstallDir REG_SZ C:\ArcGIS\Pro\<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
See, it works in Desktop.
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">with</SPAN> _winreg<SPAN class="punctuation token">.</SPAN>OpenKey<SPAN class="punctuation token">(</SPAN>_winreg<SPAN class="punctuation token">.</SPAN>HKEY_LOCAL_MACHINE<SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> r<SPAN class="string token">"SOFTWARE\WOW6432Node\ESRI\ArcGIS"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> key<SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> dt_path <SPAN class="operator token">=</SPAN> _winreg<SPAN class="punctuation token">.</SPAN>QueryValueEx<SPAN class="punctuation token">(</SPAN>key<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"InstallDir"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> dt_path
u<SPAN class="string token">'C:\\Program Files (x86)\\Common Files\\ArcGIS\\'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Is this a x64/x32 thing?