2

Is there a simple way to add and change interpreters using the Pydev plugin interface? I'm running pydev 1.6.1 and I'd like to be able to add and use a given interpreter based on a list of available interpreters in my environment.

Right now I can see the PythonInterpreterManager has a createInterpreterInfo call, but that doesn't seem to do anything. Looking at the source for pydev, it seems like I have to actually work with the preference pages to keep track of all of them.

Is there a simpler set of functions I can call to add these?

PythonInterpreterManager manager = (PythonInterpreterManager)PydevPlugin.getPythonInterpreterManager(true);
IInterpreterInfo info = manager.createInterpreterInfo(execPath, new NullProgressMonitor());
        manager.addInterpreterInfo(info);

I can already do the above, but that only caches it, but doesn't display it as a valid interpreter option in the preferences.

I've even tried doing reflection to add these without much luck. I can call addNewInput on the editor as the Add button does, but then it says it doesn't have any knowledge of that interpreter. I've tried creating a popup preferences page and adding the values to the various members via reflection as getNewInput() would, but still don't see any more options in the preference page. I'm not sure if this is because I'm missing something or the popup preference page I make is totally unrelated to the page that pops up using the Window->"Preferences" pulldown.

4

1 回答 1

0

The API is something as:

    IInterpreterManager iMan = PydevPlugin.getPythonInterpreterManager(true);
    IInterpreterInfo interpreterInfo = iMan.createInterpreterInfo("c:/python/python.exe", monitor, false);
    iMan.setInfos(new IInterpreterInfo[]{interpreterInfo}, null, null);

Note that if you have 'manager.addInterpreterInfo' in there, you probably have an old version of PyDev... (and at that call you set all the interpreters available, so, if you want to keep some configuration, you should query it and add them back).

You can use: org.python.pydev.editor.codecompletion.revisited.javaintegration.AbstractWorkbenchTestCase.createPythonInterpreterManager(NullProgressMonitor) as a reference.

于 2012-05-17T22:10:58.850 回答