srusskih / SublimeJEDI

awesome Python autocompletion with SublimeText
MIT License
938 stars 109 forks source link

Lookup Error, Could not get version information for 'python' #326

Open alexandermatthias opened 3 years ago

alexandermatthias commented 3 years ago

Hi All,

I am still a beginner, so bear with me. My immediate problem is that am having trouble getting Jedi to autocomplete for python 2.7.16, but the ultimate goal is to set up Sublime Text to develop IronPython code that will ultimately be run in Rhino.

I have just done a clean install of Sublime Text 4 and Jedi v0.18.0, as well as a clean install of Python 2.7.16. Here is a complete print-out from the console that I receive when I try to test Jedi autocomplete:

DPI mode: per-monitor v2
startup, version: 4107 windows x64 channel: stable
executable: /C/Program Files/Sublime Text/sublime_text.exe
application: /C/Program Files/Sublime Text
working dir: /C/Program Files/Sublime Text
packages path: /C/Users/Alexanderj/AppData/Roaming/Sublime Text/Packages
state path: /C/Users/Alexanderj/AppData/Roaming/Sublime Text/Local
zip path: /C/Program Files/Sublime Text/Packages
zip path: /C/Users/Alexanderj/AppData/Roaming/Sublime Text/Installed Packages
ignored_packages: ["Vintage"]
scan: /C/Users/Alexanderj/AppData/Roaming/Sublime Text/Packages/Jedi - Python autocompletion/dependencies/jedi/third_party/django-stubs/django-stubs/contrib/sessions/management has been seen before, skipping (using content fingerprint) previous path: /C/Users/Alexanderj/AppData/Roaming/Sublime Text/Packages/Jedi - Python autocompletion/dependencies/jedi/third_party/django-stubs/django-stubs/contrib/sitemaps/management fingerprint: 2844445528725461925
pre session restore time: 0.187352
startup time: 0.258352
first paint time: 0.260352
reloading python 3.3 plugin 0_package_control_loader.00-package_control
reloading python 3.3 plugin 0_package_control_loader.01-pygments
reloading python 3.3 plugin 0_package_control_loader.50-markupsafe
reloading python 3.3 plugin 0_package_control_loader.50-python-markdown
reloading python 3.3 plugin 0_package_control_loader.51-python-jinja2
reloading python 3.3 plugin 0_package_control_loader.55-mdpopups
reloading python 3.3 plugin Package Control.1_reloader
reloading python 3.3 plugin Package Control.2_bootstrap
reloading plugin Default.arithmetic
reloading plugin Default.auto_indent_tag
reloading plugin Default.block
reloading plugin Default.colors
reloading plugin Default.comment
reloading plugin Default.convert_color_scheme
reloading plugin Default.convert_syntax
reloading plugin Default.copy_path
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.html_print
reloading plugin Default.indentation
reloading plugin Default.install_package_control
reloading plugin Default.keymap
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.profile
reloading plugin Default.quick_panel
reloading plugin Default.rename
reloading plugin Default.run_syntax_tests
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.settings
reloading plugin Default.show_scope_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.ui
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin ShellScript.ShellScript
reloading python 3.3 plugin Package Control.Package Control
reloading python 3.3 plugin Jedi - Python autocompletion.__init__
plugins loaded
reloading settings Packages/User/Package Control.sublime-settings
Package Control: No updated packages
Traceback (most recent call last):
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\api\environment.py", line 75, in _get_subprocess
    info = self._subprocess._send(None, _get_info)
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\inference\compiled\subprocess\__init__.py", line 311, in _send
    is_exception, traceback, result = pickle_load(self._get_process().stdout)
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\_compatibility.py", line 396, in pickle_load
    return pickle.load(file, encoding='bytes')
LookupError: unknown encoding: bytes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\sublime_jedi\daemon.py", line 69, in _async_summon
    answer = ask_daemon_sync(view, ask_type, ask_kwargs, location)
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\sublime_jedi\daemon.py", line 53, in ask_daemon_sync
    *_prepare_request_data(view, location)
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\sublime_jedi\daemon.py", line 146, in request
    filename=filename,
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\sublime_jedi\facade.py", line 42, in __init__
    project=project,
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\api\__init__.py", line 185, in __init__
    project, environment=environment, script_path=self.path
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\inference\__init__.py", line 90, in __init__
    self.compiled_subprocess = environment.get_inference_state_subprocess(self)
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\api\environment.py", line 114, in get_inference_state_subprocess
    return InferenceStateSubprocess(inference_state, self._get_subprocess())
  File "C:\Users\Alexanderj\AppData\Roaming\Sublime Text\Packages\Jedi - Python autocompletion\dependencies\jedi\api\environment.py", line 80, in _get_subprocess
    exc))
jedi.api.environment.InvalidPythonEnvironment: Could not get version information for 'python': LookupError('unknown encoding: bytes',)

Here is a screenshot of Sublime Text 4, so you can see what I see: image

And here is a link to the stubs that I am ultimately trying to use. It seems like I need to get Jedi working on standard python autocomplete before attempting to get the stubs to work though.... More info here

SigmaTel71 commented 1 year ago

I am very late to the party, huh... but I had faced the same issue. The most awful solution I came up with is to comment out some lines in Jedi modules themselves.

In dependencies/jedi/_compatibility.py comment out lines 395 and 396, which are:

def pickle_load(file):
    try:
        # if is_py3: # <-- line 395
        #    return pickle.load(file, encoding='bytes')
        return pickle.load(file)
    # Python on Windows don't throw EOF errors for pipes. So reraise them with
    # the correct type, which is caught upwards.
    except OSError:
        if sys.platform == 'win32':
            raise EOFError()
        raise

In dependencies/jedi/api/environment.py comment lines 99-101.

        # py2 sends bytes via pickle apparently?!
        # if self.version_info.major == 2: # <-- line 99
            # self.executable = self.executable.decode()
            # self.path = self.path.decode()

        # Adjust pickle protocol according to host and client version.
        self._subprocess._pickle_protocol = highest_pickle_protocol([
            sys.version_info, self.version_info])

Before doing these changes, make sure that your .sublime-project file uses Python 2.7 interpreter, which is defined in settings['python_interpreter'] section.

After that, autocompletion should start working as intended, but its speed is sorta sluggish. Better than nothing, still...

SigmaTel71 commented 9 months ago

More 'updates' on the problem. With my own 'fix' the plugin works for a while, but some time after it may explode in very long traceback... and I have no idea how to fix this for real or at least mitigate.

UPD: or I have an idea! But I'm not sure if this change affects Python 3.x scenarios. In dependencies/jedi/_compatibility.py replace encoding 'bytes' on line 396 with 'latin-1':

def pickle_load(file):
    try:
        if is_py3:
           return pickle.load(file, encoding='latin-1') # <-- line 396
        return pickle.load(file)
    # Python on Windows don't throw EOF errors for pipes. So reraise them with
    # the correct type, which is caught upwards.
    except OSError:
        if sys.platform == 'win32':
            raise EOFError()
        raise

Speaking of dependencies/jedi/api/environment.py:99-101, I had a rather interesting result. My project uses Python 2.7.7, but self.executable and self.path don't have to be additionaly .decode()'d. They print normally as is.