ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

Plugin cannot be loaded #79

Closed Maweypeyyu closed 9 years ago

Maweypeyyu commented 9 years ago

Hi,

on my system after installing tern_for_sublime (either from package-control or via git clone) I get the following error message in sublime's console:

Reloading plugin /home/testuser/.config/sublime-text-2/Packages/tern_for_sublime/tern.py
Traceback (most recent call last):
  File "./sublime_plugin.py", line 62, in reload_plugin
  File "./tern.py", line 9, in <module>
    from .utils.renderer import create_arghints_renderer
ValueError: Attempted relative import in non-package

python: 2.7.9 sublime-text2: v2221 linux x64 channel: stable os: debian jessy

You can simply fix it by adding the following line as the first line to utils/renderer.py:

# encoding=utf8

Best wishes

marijnh commented 9 years ago

The try/except around the import is intended to take care of this. I wonder why the first (non-relative) import fails.

Adding an encoding declaration does not help at all when I create a test case for this problem. How would that help?

marijnh commented 9 years ago

Actually, the encoding declaration does work (but only in the context of ST2, not raw python2.7). I have tried to look around to figure out why it would work, but couldn't find anything. Still interested in an explanation, but in the meantime, attached patch adds the magic comment.