This project has moved and is read-only. For the latest updates, please go here.

Setting Interpreter Programmatically

Mar 12, 2012 at 4:07 PM
Edited Mar 12, 2012 at 5:24 PM


I am trying to set the Python interpreter programmatically using the DTE object ( trying to get the interptreter properties using :  dte.get_Properties( categoryName, pageName ); )

The problem is that I don't know the name of the category and page of the Python Tools Iterpreter properties.

By looking at the Regedit.exe under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\10.0_Config\AutomationProperties, it's suppose to be: "Python Tools" as a category and "Interpreters" as a page name, but

dte.get_Properties("Python Tools", "Interpreters")

throws an exception in that case. It does work with dte.get_Properties("Python Tools", "Advanced")

Can you please point me to how can I get the Python Interpreter options programmatically?

Thank you,


Mar 12, 2012 at 6:42 PM

I think it's "Python Tools", "Interpreter Options".  There's a seperate resource ID which we pass in which seems to have a slightly different string.

Mar 12, 2012 at 7:02 PM

I tried that - it didn't work as well. Though the exception is different:

When I use "Interpreter Options" or any other string ( for which page doesn't exist ) I get the following exception:

-  dte.get_Properties( "Python Tools", "Interpreter Options" ) 'dte.get_Properties( "Python Tools", "Interpreter Options" )' threw an exception of type 'System.Runtime.InteropServices.COMException' EnvDTE.Properties {System.Runtime.InteropServices.COMException}
+  base {"Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))"} System.Runtime.InteropServices.ExternalException {System.Runtime.InteropServices.COMException}

While when I use "Interpreters" I get the following exception:

-  dte.get_Properties( "Python Tools", "Interpreters" ) 'dte.get_Properties( "Python Tools", "Interpreters" )' threw an exception of type 'System.InvalidCastException' EnvDTE.Properties {System.InvalidCastException}
+  base {"Specified cast is not valid."} System.SystemException {System.InvalidCastException}

Looks like "Interpreters" is the right page but there is some casting error when I try to retreive it.

Mar 12, 2012 at 7:26 PM

Ok, I'll take a look tomorrow or Wednesday after getting back from PyCon and see if I can figure out why it's not working. 

Mar 12, 2012 at 7:26 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Mar 12, 2012 at 7:28 PM

OK, thank you very much!

Mar 15, 2012 at 12:31 AM

Thanks for the report, I've checked in a fix for this, "Interpreters" is the right one, our options page wasn't public + COM visible which is the reason for the failed cast.  After this change you should be able to do:

var props = VsIdeTestHostContext.Dte.get_Properties("Python Tools", "Interpreters");
props.Item("DefaultInterpreter").Value = Guid.Empty;
props.Item("DefaultInterpreterVersion").Value = "2.7";

Codeplex source control is giving issues so I don't have a link to the exact change set yet.