pythonautocompletesubprocessscintillapython-jedi

Is it possible to embed Jedi in an application on a system where Python is not installed?


I'm working on an (Windows and Mac) application that uses Python as an embedded scripting language.

The application includes an internal text editor, implemented using Scintilla, and I'm using Jedi for autocompletion, which generally works great.

However, when attempting autocompletion on a computer that does not have a separate installation of Python, Jedi raises an error:

jedi.api.environment.InvalidPythonEnvironment:

Could not get version information for 'python':

FileNotFoundError(2, 'The system cannot find the file specified', None, 2, None)

Digging into the code, I can see that the underlying code that is throwing the FileNotFoundError is when Jedi attempts to run python using subprocess.Popen. Python is not installed on the computer, so this fails.

I can also reproduce the same issue on a computer that does have Python installed by editing my Path environment variable not to include the location of python.exe.

Ideally, we don't want users of our application to have to install Python just to get autocompletion working.

My questions:

  1. Is it possible to get Jedi not to spawn subprocesses, and instead run its code inside the same instance of Python within which it itself is running? I couldn't find anything about this in the documentation or the source code that deals with Environments, and extrapolating from the discussion here I suspect the answer might be no.

  2. Is it possible somehow to get Jedi to use the same python37.dll that our application is using for its functionality, instead of looking for a .exe file that does not exist?

  3. Is there any way we could make some kind of minimal Python installation within our existing app installation that uses the same DLLs/Python Lib etc? How could I go about doing this?

  4. Is there any other way to get Jedi autocompletion working in our app without requiring the user to install Python, or including a full Python installer as part of our build process?


Solution

    1. Is it possible to get Jedi not to spawn subprocesses, and instead run its code inside the same instance of Python within which it itself is running? I couldn't find anything about this in the documentation or the source code that deals with Environments, and extrapolating from the discussion here I suspect the answer might be no.

    This is definitely possible. All the tools are there. There are discussions ongoing here: https://github.com/davidhalter/jedi-vim/issues/870.

    IMO a patch to Jedi is needed that uses an jedi.api.environment.InterpreterEnvironment in some cases like yours. It's definitely possible, it's just buggy at the moment.