Pylint 无法与 OS X 上的 Emacs GUI 一起使用;从命令行工作
当从命令行 (emacs filename.py
) 运行时,flymake 和 pylint 可以完美地协同工作。错误被正确突出显示。 (尽管我无法通过工具提示悬停来获取错误详细信息,因为它是文本模式。)
从 GUI (Carbon Emacs) 运行时,Flymake 会立即返回,并且文件中的第一行会突出显示错误“in < ;模块>
”。第一行甚至在“Hello World”脚本上也显示错误。)我想让它在 GUI 模式下正常工作,以便我可以用鼠标导航(我知道,我知道)并使用工具提示来获取详细信息pylint 上报告错误。
我使用“easy_install pylint
”安装了 pylint,pylint 和 epylint 脚本位于“~/py/scripts
”中。我将该目录添加到我的 .bashrc 中的 PATH 中:(
export PATH=$PATH:~/py/scripts
我的 .profile 是我的 .bashrc 的符号链接。)
我意识到 Emacs-GUI 没有从我的 .bashrc 加载路径,所以我创建了一个 ~/.MacOSX/ environment.plist 文件,使用我在终端中看到的完整 PATH 设置 PATH 变量。
现在,在 Emacs-GUI“(getenv "PATH")
" 中,输出显示正确:
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/schof/py/scripts:/usr/X11R6/bin"
同样,“Ch v exec-path
”的输出显示正确:
("/usr/bin" "/bin" "/usr/sbin" "/sbin" "/usr/local/bin" "/usr/local/git/bin" "/usr/X11/bin" "/Users/schof/py/scripts" "/Applications/Emacs.app/Contents/MacOS/libexec" "/Applications/Emacs.app/Contents/MacOS/bin" "/usr/X11R6/bin")
这让我对于我应该如何解决这个问题没有进一步的想法。我绝不是 emacs 专家,所以我可能在这里遗漏了一些明显的东西;请随时询问更多详情。
操作系统 X 10.6.7;碳 Emacs 22.3.1;皮林特 0.23.0。
.emacs 中的 Flymake / Pylint 代码:
(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "epylint" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pylint-init)))
;; Auto-start flymake-mode when you go into python-mode
(add-hook 'python-mode-hook
'(lambda ()
(setq python-indent 4)
(flymake-mode)))
更新 2011-04-05 以响应 @sanityinc 的回答:
Flymake 在 *messages*
中的详细级别 3 输出:(这不让问题的根源对我来说显而易见。)
starting syntax check as new-line has been seen
flymake is running: nil
file /Users/schof/pytest.py, init=flymake-pylint-init [3 times]
create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.py
saved buffer pytest.py in file /Users/schof/pytest_flymake.py
started process 3221, command=(epylint pytest_flymake.py), dir=/Users/schof/
received 704 byte(s) of output from process 3221
file /Users/schof/pytest.py, init=flymake-pylint-init
parsed 'Traceback (most recent call last):', no line-err-info
parse line: file-idx=2 line-idx=3 file=/Users/schof/py/scripts/epylint line=4 text=in <module>
get-real-file-name: file-name=/Users/schof/py/scripts/epylint real-name=~/py/scripts/epylint
parsed ' File "/Users/schof/py/scripts/epylint", line 4, in <module>', got line-err-info
parsed ' import pkg_resources', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=2556 text=in <module>
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2556, in <module>', got line-err-info
parsed ' working_set.require(__requires__)', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=620 text=in require
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 620, in require', got line-err-info
parsed ' needed = self.resolve(parse_requirements(requirements))', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=518 text=in resolve
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 518, in resolve', got line-err-info
parsed ' raise DistributionNotFound(req) # XXX put more info here', no line-err-info
parsed 'pkg_resources.DistributionNotFound: pylint==0.23.0', no line-err-info
file /Users/schof/pytest.py, init=flymake-pylint-init
process 3221 exited with code 1
cleaning up using flymake-simple-cleanup
deleted file /Users/schof/pytest_flymake.py
created an overlay at (1-18)
pytest.py: 4 error(s), 0 warning(s) in 0.47 second(s)
为了进行比较,这里是从 emacs 文本模式运行时 Flymake verbosity 3 的输出。 “hello world”文件通过了所有 pylint 测试。
starting syntax check as new-line has been seen
flymake is running: nil
file /Users/schof/pytest.py, init=flymake-pylint-init [3 times]
create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.py
saved buffer pytest.py in file /Users/schof/pytest_flymake.py
started process 3395, command=(epylint pytest_flymake.py), dir=/Users/schof/
file /Users/schof/pytest.py, init=flymake-pylint-init
process 3395 exited with code 0
cleaning up using flymake-simple-cleanup
deleted file /Users/schof/pytest_flymake.py
pytest.py: 0 error(s), 0 warning(s) in 0.30 second(s)
When run from the command-line (emacs filename.py
) flymake and pylint work perfectly together. Errors are highlighted properly. (Although I can't tooltip hover to get error details because it's text-mode.)
When run from the GUI (Carbon Emacs) Flymake returns immediately, and the first line in the file is highlighted with the error "in <module>
". The first line is shows the error even on a "Hello World" script.) I'd like to get it working properly in GUI mode so that I can navigate with the mouse (I know, I know) and use tooltips to get details on the pylint reported errors.
I installed pylint with "easy_install pylint
", and the pylint and epylint scripts are in "~/py/scripts
". I added that directory to my PATH in my .bashrc:
export PATH=$PATH:~/py/scripts
(My .profile is a symlink to my .bashrc.)
I realized that Emacs-GUI was not loading the path from my .bashrc, so I created a ~/.MacOSX/environment.plist file, setting the PATH variable with the full PATH I see in the terminal.
Now in Emacs-GUI "(getenv "PATH")
" the output appears correct:
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/Users/schof/py/scripts:/usr/X11R6/bin"
Similarly, the output of "C-h v exec-path
" appears correct:
("/usr/bin" "/bin" "/usr/sbin" "/sbin" "/usr/local/bin" "/usr/local/git/bin" "/usr/X11/bin" "/Users/schof/py/scripts" "/Applications/Emacs.app/Contents/MacOS/libexec" "/Applications/Emacs.app/Contents/MacOS/bin" "/usr/X11R6/bin")
That leaves me with no further ideas for how I should resolve this. I'm by no means an emacs guru, so it's possible I'm missing something obvious here; feel free to ask for more details.
OS X 10.6.7; Carbon Emacs 22.3.1; pylint 0.23.0.
Flymake / Pylint code from .emacs:
(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "epylint" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pylint-init)))
;; Auto-start flymake-mode when you go into python-mode
(add-hook 'python-mode-hook
'(lambda ()
(setq python-indent 4)
(flymake-mode)))
Update 2011-04-05 in response to @sanityinc's answer:
Verbosity level 3 output of flymake in *messages*
: (This does not make the source of the problem obvious to me.)
starting syntax check as new-line has been seen
flymake is running: nil
file /Users/schof/pytest.py, init=flymake-pylint-init [3 times]
create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.py
saved buffer pytest.py in file /Users/schof/pytest_flymake.py
started process 3221, command=(epylint pytest_flymake.py), dir=/Users/schof/
received 704 byte(s) of output from process 3221
file /Users/schof/pytest.py, init=flymake-pylint-init
parsed 'Traceback (most recent call last):', no line-err-info
parse line: file-idx=2 line-idx=3 file=/Users/schof/py/scripts/epylint line=4 text=in <module>
get-real-file-name: file-name=/Users/schof/py/scripts/epylint real-name=~/py/scripts/epylint
parsed ' File "/Users/schof/py/scripts/epylint", line 4, in <module>', got line-err-info
parsed ' import pkg_resources', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=2556 text=in <module>
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2556, in <module>', got line-err-info
parsed ' working_set.require(__requires__)', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=620 text=in require
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 620, in require', got line-err-info
parsed ' needed = self.resolve(parse_requirements(requirements))', no line-err-info
parse line: file-idx=2 line-idx=3 file=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py line=518 text=in resolve
get-real-file-name: file-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py real-name=/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py
parsed ' File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 518, in resolve', got line-err-info
parsed ' raise DistributionNotFound(req) # XXX put more info here', no line-err-info
parsed 'pkg_resources.DistributionNotFound: pylint==0.23.0', no line-err-info
file /Users/schof/pytest.py, init=flymake-pylint-init
process 3221 exited with code 1
cleaning up using flymake-simple-cleanup
deleted file /Users/schof/pytest_flymake.py
created an overlay at (1-18)
pytest.py: 4 error(s), 0 warning(s) in 0.47 second(s)
For comparison, here is the output from flymake verbosity 3 when run from emacs text mode. The "hello world" file passed all pylint tests.
starting syntax check as new-line has been seen
flymake is running: nil
file /Users/schof/pytest.py, init=flymake-pylint-init [3 times]
create-temp-inplace: file=/Users/schof/pytest.py temp=/Users/schof/pytest_flymake.py
saved buffer pytest.py in file /Users/schof/pytest_flymake.py
started process 3395, command=(epylint pytest_flymake.py), dir=/Users/schof/
file /Users/schof/pytest.py, init=flymake-pylint-init
process 3395 exited with code 0
cleaning up using flymake-simple-cleanup
deleted file /Users/schof/pytest_flymake.py
pytest.py: 0 error(s), 0 warning(s) in 0.30 second(s)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了更清楚地看到出了什么问题,请增加 Flymake 的日志级别,然后查看
*messages*
:没有这些信息,我不会推测可能的问题。
顺便说一句,有一个技巧可以避免使用
environment.plist
方法;你可以让 Emacs 向你的常规 shell 询问你的首选路径:(这是从 我的 Emacs 配置 ,其中有一堆 Flymake 代码,包括使用
pyflakes
的 Python 配置,因此您可能想看一下。)更新:现在您已经添加了详细输出,我看到您的 ~/py/epylint 程序找不到
pkg_resources
,这表明PYTHONPATH
是错误的。因此,使用上述技术的变体,尝试以下操作:To more clearly see what's going wrong, increase flymake's log level, then look in
*messages*
:Without that info, I wouldn't speculate on the likely problem.
There's a trick for avoiding the
environment.plist
approach, BTW; you can get Emacs to ask your regular shell for your preferred PATH:(That's lifted from my Emacs config, which has a bunch of flymake code in it, including a config for python using
pyflakes
, so you might want to take a look.)Update: Now that you've added the verbose output, I see that your ~/py/epylint program can't find
pkg_resources
, which points toPYTHONPATH
being wrong. So, using a variation on the above technique, try this: