SublimeLinter / SublimeLinter-pylint

SublimeLinter plugin for python, using pylint.
MIT License
116 stars 23 forks source link

Cannot get pylint operational #14

Closed robwilkerson closed 9 years ago

robwilkerson commented 9 years ago

I kind of hate creating an issue for this since I'm quite sure it's a me problem (I'm new to Python dev), but it seems like that's the preferred way of asking for help. Anyway, for the life of me, I cannot seem to get this to work. I've been working on this for hours now and reading everything I can find, but either nothing is working or I'm just not understanding it well enough to do it right. I'm hoping someone can point me in the right direction. Don't be afraid to get remedial.

I'm running Sublime Text (build 3065) on OS X. Python 2.7.9 is installed via Homebrew and pylint was installed via pip install pylint. I'm working on a few scripts using Python 2.7 and they all begin with #!/usr/bin/env python.

Relevant Console Output

$ which python
/usr/local/bin/python
$ python --version
Python 2.7.9
$ which pylint
/usr/local/bin/pylint
$ pylint --version
No config file found, using default configuration
pylint 1.4.1,
astroid 1.3.4, common 0.63.2
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]

SublimeLinter Settings (linters > pylint snippet)

 "pylint": {
  "@disable": false,
  "@python": "2.7",
  "args": [],
  "disable": "",
  "enable": "",
  "excludes": [],
  "paths": [],
  "rcfile": "",
  "show-codes": true
}

Sublime Console Output

startup time: 0.992911
launching: /Users/robwilkerson/Dropbox/Applications/Sublime Text.app/Contents/MacOS/plugin_host
loaded 1760 snippets
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
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.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin Vintage.vintage
Traceback (most recent call last):
  File "/Users/robwilkerson/Dropbox/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "./importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "/Users/robwilkerson/Dropbox/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 671, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "/Users/robwilkerson/Dropbox/Library/application_support/sublimetext3/Packages/Vintage/vintage.py", line 307
    print "invalid motion mode:", mode
                               ^
SyntaxError: invalid syntax
reloading plugin Vintage.vintage_commands
reloading plugin Vintage.vintage_motions
Traceback (most recent call last):
  File "/Users/robwilkerson/Dropbox/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "./importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "/Users/robwilkerson/Dropbox/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 671, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "/Users/robwilkerson/Dropbox/Library/application_support/sublimetext3/Packages/Vintage/vintage_motions.py", line 3, in <module>
    from vintage import transform_selection
ImportError: No module named 'vintage'
reloading plugin 0_package_control_loader.00-package_control
reloading plugin 0_package_control_loader.02-bz2
reloading plugin Block Cursor Everywhere.SublimeBlockCursor
reloading plugin BracketHighlighter.bh_core
reloading plugin BracketHighlighter.bh_logging
reloading plugin BracketHighlighter.bh_plugin
reloading plugin BracketHighlighter.bh_regions
reloading plugin BracketHighlighter.bh_remove
reloading plugin BracketHighlighter.bh_rules
reloading plugin BracketHighlighter.bh_search
reloading plugin BracketHighlighter.bh_swapping
reloading plugin BracketHighlighter.bh_wrapping
reloading plugin BracketHighlighter.ure
reloading plugin Colorsublime.colorsublime-plugin
reloading plugin Copy to HipChat.copy_to_hipchat
reloading plugin EditorConfig.EditorConfig
reloading plugin GitGutter.git_gutter
reloading plugin GitGutter.git_gutter_change
reloading plugin GitGutter.git_gutter_compare
reloading plugin GitGutter.git_gutter_events
reloading plugin GitGutter.git_gutter_handler
reloading plugin GitGutter.git_helper
reloading plugin GitGutter.view_collection
reloading plugin HTML5.encode_html_entities
reloading plugin HTML5.html_completions
reloading plugin Insert Callback.Callback
reloading plugin Local History.history
reloading plugin MarkdownEditing.bootstrap
reloading plugin MarkdownEditing.custom_find_under_expand
reloading plugin MarkdownEditing.distraction_free_mode
reloading plugin MarkdownEditing.footnotes
reloading plugin MarkdownEditing.gather_missing_links
reloading plugin MarkdownEditing.indent_list_item
reloading plugin MarkdownEditing.indent_list_multiitem
reloading plugin MarkdownEditing.insert_references
reloading plugin MarkdownEditing.jumpToMarker
reloading plugin MarkdownEditing.lint
reloading plugin MarkdownEditing.list_markdown_references
reloading plugin MarkdownEditing.numbered_list
reloading plugin MarkdownEditing.paste_as_link
reloading plugin MarkdownEditing.paste_as_reference
reloading plugin MarkdownEditing.quote_indenting
reloading plugin MarkdownEditing.underlined_headers
reloading plugin Package Control.bootstrap
reloading plugin Package Control.Package Control
reloading plugin Rsync SSH.rsync-ssh
reloading plugin RSync.RSync
reloading plugin ScopeHunter.scope_hunter
reloading plugin ScopeHunter.scope_hunter_notify
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarAPI
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading plugin sublime-github.commandline
reloading plugin sublime-github.github
reloading plugin sublime-github.sublime_github
reloading plugin sublime-github.sublime_requests
reloading plugin SublimeGit.SublimeGit
reloading plugin SublimeLinter-json.linter
SublimeLinter: json linter loaded 
reloading plugin SublimeLinter-pylint.linter
SublimeLinter: pylint linter loaded 
reloading plugin SyncedSideBar.SyncedSideBar
reloading plugin Tag.Edit
reloading plugin Tag.Tag
reloading plugin Tag.tag_classes
reloading plugin Tag.tag_close_tag
reloading plugin Tag.tag_close_tag_on_slash
reloading plugin Tag.tag_indent
reloading plugin Tag.tag_insert_as_tag
reloading plugin Tag.tag_lint
reloading plugin Tag.tag_remove
reloading plugin Tag.tag_remove_attributes
reloading plugin Vintage Escape.vintage_escape
reloading plugin Vintageous.__init__
reloading plugin Vintageous.dev_cmds
reloading plugin Vintageous.ex_commands
reloading plugin Vintageous.ex_main
reloading plugin Vintageous.ex_motions
reloading plugin Vintageous.jump_list_cmds
reloading plugin Vintageous.modelines
reloading plugin Vintageous.state
reloading plugin Vintageous.test_runner
reloading plugin Vintageous.xactions
reloading plugin Vintageous.xmotions
reloading plugin Vintageous.xsupport
reloading plugin Vintageous.xsupport_mouse
reloading plugin Alignment.Alignment
reloading plugin Default File Type.default_file_type
reloading plugin DocBlockr.__init__
reloading plugin DocBlockr.jsdocs
reloading plugin GenerateUUID.generate_uuid
reloading plugin Markdown Preview.helper
reloading plugin Markdown Preview.markdown_settings
reloading plugin Markdown Preview.markdown_wrapper
reloading plugin Markdown Preview.MarkdownPreview
reloading plugin Phpcs.phpcs
reloading plugin ReadmePlease.ReadmePlease
reloading plugin SmartMarkdown.headline
reloading plugin SmartMarkdown.headline_level
reloading plugin SmartMarkdown.headline_move
reloading plugin SmartMarkdown.pandoc_render
reloading plugin SmartMarkdown.smart_folding
reloading plugin SmartMarkdown.smart_list
reloading plugin SmartMarkdown.smart_table
reloading plugin SmartMarkdown.table
reloading plugin SmartMarkdown.utilities
reloading plugin SublimeCodeIntel.ordereddict
reloading plugin SublimeCodeIntel.SublimeCodeIntel
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
reloading plugin SublimeLinter-jshint.linter
SublimeLinter: jshint linter loaded 
reloading plugin SublimeLinter-php.linter
SublimeLinter: php linter loaded 
reloading plugin SublimeREPL.__init__
reloading plugin SublimeREPL.completions
reloading plugin SublimeREPL.lang_integration
reloading plugin SublimeREPL.run_existing_command
reloading plugin SublimeREPL.sublimerepl
reloading plugin SublimeREPL.sublimerepl_build_system_hack
reloading plugin SublimeREPL.text_transfer
plugins loaded
SublimeLinter: debug mode: on 
SublimeLinter: temp directory: /var/folders/21/99c8gzcn7lz9dx__973hbj940000gn/T/SublimeLinter3-robwilkerson 
SublimeLinter: find_python(version='3', script=None, module=None) 
SublimeLinter: find_python: requested version = {'major': 3, 'minor': None} 
SublimeLinter: user shell: /bin/zsh 
SublimeLinter: computed PATH using /bin/zsh:
~/.nvm/v0.10.33/bin/
/usr/local/bin/
/Users/robwilkerson/.nvm/v0.10.33/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

SublimeLinter: find_posix_python: python3 => None 
SublimeLinter: find_posix_python: python3 => None 
SublimeLinter: find_posix_python: python => /usr/local/bin/python 
SublimeLinter: find_python: system python = /usr/local/bin/python 
SublimeLinter: find_python: available version = {'major': 2, 'minor': 7} 
SublimeLinter: find_python: <= (None, None, 2, 7) 
SublimeLinter: no python 3 available to augment sys.path 
SublimeLinter: find_python(version=None, script='pylint', module=None) 
SublimeLinter: find_python: default python = /usr/local/bin/python 
SublimeLinter: find_python: available version = {'major': 2, 'minor': 7} 
SublimeLinter: find_python: 'pylint' path = /usr/local/bin/pylint 
SublimeLinter: find_python: <= ('/usr/local/bin/python', '/usr/local/bin/pylint', 2, 7) 
SublimeLinter: pylint version query: /usr/local/bin/python /usr/local/bin/pylint --version 
SublimeLinter: WARNING: no pylint version could be extracted from:
Traceback (most recent call last):
  File "/usr/local/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Library/Python/2.7/site-packages/pylint/__init__.py", line 22, in run_pylint
    from pylint.lint import Run
  File "/Library/Python/2.7/site-packages/pylint/lint.py", line 43, in <module>
    import astroid
  File "/Library/Python/2.7/site-packages/astroid/__init__.py", line 54, in <module>
    from astroid.nodes import *
  File "/Library/Python/2.7/site-packages/astroid/nodes.py", line 40, in <module>
    from astroid.node_classes import Arguments, AssAttr, Assert, Assign, \
  File "/Library/Python/2.7/site-packages/astroid/node_classes.py", line 23, in <module>
    import six
ImportError: No module named six

SublimeLinter: found existing HTML syntax, version 3 
found 57 files for base name Main.sublime-menu
SublimeLinter: found existing Rails syntax, version 1 
Package Control: No updated packages
bgreenlee commented 9 years ago

What do you get if you run: /usr/local/bin/python /usr/local/bin/pylint --version?

robwilkerson commented 9 years ago

Hmmm. Using the absolute path, I get the same as above. That seems weird. Why would that be since it's in my PATH and which picks up both executables at that location.

NotSqrt commented 9 years ago

Can you cat the content of /usr/local/bin/pylint ?

I've also seen strange behaviours when there are multiple versions of pylint on a system.

robwilkerson commented 9 years ago
$ cat /usr/local/bin/pylint
#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pylint import run_pylint

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(run_pylint())
NotSqrt commented 9 years ago

pylint < 1.4.0:

# EASY-INSTALL-ENTRY-SCRIPT: 'pylint==1.3.1','console_scripts','pylint'
__requires__ = 'pylint==1.3.1'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pylint==1.3.1', 'console_scripts', 'pylint')()
    )

pylint >= 1.4.0:

# -*- coding: utf-8 -*-
import re
import sys

from pylint import run_pylint

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(run_pylint())

So it is notably different..

I have not tested pylint 1.4 at the moment. All I can suggest is to force a reinstall of pylint ...

bgreenlee commented 9 years ago

Note too that pylint is using /usr/bin/python, whereas your default python is in /usr/local/bin.

robwilkerson commented 9 years ago

Grr. Used pip to uninstall and reinstall pylint, but it's still using /usr/bin/python (which is v2.7.6). The Homebrew installed Python is v2.7.9, for whatever that's worth. Am I doing something wrong in my setup? I don't do much Python dev, so there could be nuances of the configuration that I've missed or done incorrectly.

NotSqrt commented 9 years ago

Was your pip installed with /usr/bin/python or the Homebrew version ?

bgreenlee commented 9 years ago

I'm not sure how that's happening. You could try manually editing the pylint file and changing that to /usr/local/bin/python.

NotSqrt commented 9 years ago

I'm not sure if the shebang line is important, since sublimelinter forces the use of /usr/local/bin/python but it's worrth a try !

robwilkerson commented 9 years ago

@NotSqrt To be honest, I'm not sure when/where/how pip was installed. At this point, I can only see that it's using the pip executable in /usr/local/bin/. A little reading seems to indicate that pip is installed automatically when installing Python via Homebrew. I'm going to try modifying the shebang now and see if that just gets things working.

robwilkerson commented 9 years ago

Well, guess not. I still get the same error(s) after modifying the shebang path. I'm not sure what's going on in my ecosystem that has things all bound up like this.

robwilkerson commented 9 years ago

And behind door #3 was the nuclear option. Uninstall pylint, uninstall all Python versions installed by Homebrew (apparently there were multiple--who knew?), reinstall pip. Apparently this is the price I pay for not having done enough Python development, but things do seem to be working okay using the native OSX Python executable.

Thanks for your help, everyone.

NotSqrt commented 9 years ago

That was definitely a strange problem, no matter what your python experience was ..

trinitronx commented 7 years ago

Ran into same issue myself having installed python, pip and pylint via Homebrew. As such, the paths to the executables in my python environment were:

Although my PATH and PYTHONPATH settings were correct to prefer the Homebrew python environment paths, there was one problem:

In order to check how the Pylinter Sublime Text Package was starting pylint, I added a couple debug lines into the Pylinter code to check what it was using for python_bin, and pylint_path:

--- Packages/Pylinter/pylinter.py   2017-01-02 18:15:53.000000000 -0700
+++ Packages/Pylinter/pylinter.py   2017-01-02 18:15:58.000000000 -0700
@@ -178,6 +178,8 @@
         try:
             python_bin = cls.get_or('python_bin', 'python')
             pylint_path = cls.get_or('pylint_path', None)
+            speak("python_bin %s" % python_bin)
+            speak("pylint_path %s" % pylint_path)
             if pylint_path is None:
                 _ = subprocess.Popen("pylint",
                                  stdout=subprocess.PIPE,

The error message in Sublime Text console was:

reloading plugin Pylinter.multiconf
reloading plugin Pylinter.pylinter
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
plugins loaded
SublimeLinter: debug mode: off 
SublimeLinter: pylint activated: ('/usr/local/bin/python', '/usr/local/bin/pylint') 
 - PyLinter: python_bin python
 - PyLinter: pylint_path None
 - PyLinter: Pylint executable *not* found
 - PyLinter: Seaching for lint.py module...
error: Pylinter could not automatically determined the path to `lint.py`.

Please provide one in the settings file using the `pylint_path` variable.

NOTE:
If you are using a Virtualenv, the problem might be resolved by launching Sublime Text from correct Virtualenv.
Traceback (most recent call last):
  File "/opt/homebrew-cask/Caskroom/sublime-text3/Build 3083/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 210, in on_api_ready
    m.plugin_loaded()
  File "/Users/jcuzella/Library/Application Support/Sublime Text 3/Packages/Pylinter/pylinter.py", line 78, in plugin_loaded
    PYLINT_VERSION = PylSet.get_lint_version()
  File "/Users/jcuzella/Library/Application Support/Sublime Text 3/Packages/Pylinter/pylinter.py", line 241, in get_lint_version
    command = list(DEFAULT_PYLINT_COMMAND)
TypeError: 'NoneType' object is not iterable

Solution:

Because I preferred Homebrew for managing my python and pip versions, I edited the shim file and replaced the shebang line at the top with: #!/usr/local/bin/python to force the Homebrew python. Alternatively, it looks like I could have set pylint_path in my Sublime Text settings somewhere, but I could not get this to work (maybe I did not use the correct setting json variable name or type?).

--- /usr/local/bin/pylint   2017-01-02 18:56:16.000000000 -0700
+++ /usr/local/bin/pylint   2017-01-02 18:56:30.000000000 -0700
@@ -1,4 +1,4 @@
-#!/usr/local/opt/python/bin/python2.7
+#!/usr/local/bin/python

 # -*- coding: utf-8 -*-
 import re

After the fix, I quit and restarted Sublime Text 3, and in the console, it found pylint fine this time without pylint_path set:

reloading plugin PyRefactor.refactor
reloading plugin SublimeLinter-pylint.linter
SublimeLinter: pylint linter loaded 
reloading plugin Surround.Surround
reloading plugin JSHint Gutter.JSHint
reloading plugin Pylinter.multiconf
reloading plugin Pylinter.pylinter
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
plugins loaded
 - PyLinter: python_bin python
 - PyLinter: pylint_path None
 - PyLinter: Pylint executable found
 - PyLinter: Pylint version (1, 6, 4) found
SublimeLinter: debug mode: off 
SublimeLinter: pylint activated: ('/usr/local/bin/python', '/usr/local/bin/pylint') 
SublimeLinter: ERROR: pylint cannot locate 'pylint@python' 
ApplySyntax: Warning: 'file_name' keyword is deprecated and will be removed in the future.
reloading plugin Pylinter.pylinter
 - PyLinter: python_bin python
 - PyLinter: pylint_path None
 - PyLinter: Pylint executable found
 - PyLinter: Pylint version (1, 6, 4) found