Custom Python (OSGeo4W) REPL exits immediately with error

Jul 20, 2012 at 7:37 PM

Hello, I have a custom python 2.7 installed as part of the OSGeo4W package, which all appears to be working correctly when I start from a Windows CMD command prompt.

 

However, when I attempt to add a custom interpreter (Debug -> Options and Settings -> Python Tools -> Interpreter Options -> Add Interpreter), I run into difficulty.

Settings are:

Path: c:\OSGeo4W\bin\python.exe

WINDOWSPATH: c:\OSGeo4W\bin\pythonw.exe

Architecture: x86

Language Version: 2.7

Path Environment Variable: PYTHONPATH

 

When I attempt to start my custom interpreter in pytools, it immediately errors out with "The Python REPL process has exited"

If I attempt to enter anything in to the blinking cursor, it gives me the error "ImportError: No module named site"

 

The paths for the OSGeo4W installation of Python include the binary being in c:\OSGeo4W\bin\ and the libs being in c:\OSGeo4W\apps\python27\lib\

 

I suspect there is something janky with the PYTHONPATH or the PYTHONHOME, but cannot figure out what is mis-configured in VisualStudio. Again, custom python interpreter works correctly when started from windows cmd prompt.

 

Any help would be greatly appreciated.

 

Ceers,

Peter

Coordinator
Jul 24, 2012 at 4:04 PM

If PYTHONPATH is set globally, then we may well be changing it to something inappropriate. You could try changing the Path Environment Variable to something else, though obviously any search paths added to the project won't show up.

Alternatively, you could add "c:\OSGeo4W\apps\python27\lib\" (and any paths in the global PYTHONPATH) to your project as a search path, which will then include them when we overwrite this variable.

CPython for Windows also loads some paths from the registry (HKLM\Software\Python\PythonCore\2.7\PythonPath). The value of this key may be incorrect, depending on how OSGeo4W packaged the installation.

Longer term, we should probably add a field to allow interpreters to have their own default PYTHONPATH value. (We can't simply use the existing global value, since that will interfere with otherwise isolated interpreters.) Let us know whether any of the above options help.