Pylint不能在OS X上使用Emacs GUI;从命令行工作 [英] Pylint not working with Emacs GUI on OS X; works from command-line

查看:169
本文介绍了Pylint不能在OS X上使用Emacs GUI;从命令行工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从命令行( emacs filename.py )运行时,flymake和pylint可以一起工作。错误突出显示正确。 (虽然我无法使用鼠标悬停来获取错误详细信息,因为它是文本模式。)



当从GUI(Carbon Emacs)运行时,Flymake会立即返回,第一个在< module> 中突出显示错误。第一行即使在Hello World脚本中也显示错误。)我希望在GUI模式下正常工作,以便我可以使用鼠标导航(我知道,我知道)并使用工具提示来获取详细信息在pylint报告错误。



我安装pylint easy_install pylint ,pylint和epylint脚本是在〜/ py / scripts 中。我将该目录添加到我的PATH中.bashrc:

  export PATH = $ PATH:〜/ py / scripts 

(我的.profile是我的.bashrc的符号链接)


$ b $我意识到Emacs-GUI没有加载我的.bashrc的路径,所以我创建了一个〜/ .MacOSX / environment.plist文件,设置PATH变量与终端中看到的完整路径。 p>

现在在Emacs-GUI(getenvPATH)输出显示正确:

 / 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 / bin/ Users / schof / py / scripts/Applications/Emacs.app/Contents/MacOS/libexec/Applications/Emacs.app/Contents/MacOS/bin/ usr / X11R6 / bin)

我没有进一步的想法来解决这个问题。我绝对不是一个emacs大师,所以有可能我在这里缺少一些明显的东西;随时要求更多的细节。



OS X 10.6.7;碳Emacs 22.3.1; pylint 0.23.0。



来自.emacs的Flymake / Pylint代码:

 (when(loadflymaket)
(defun flymake-pylint-init()
(let *((temp-file(flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(本地文件(文件相对名称
temp-file
(file-name-directory buffer-file-name)) )
(列表epylint(列表本地文件))))

(add-to-list'flymake-allowed-file-name-masks
' \\.py\\flymake-pylint-init)))


;;当你进入python模式时,自动启动flymake模式
(add-hook'python-mode-hook
'(lambda()
(setq python-indent 4)
(flymake-mode)))

更新2011-04-05响应@ sanityinc的答案:



*消息* 中的flymake的详细级别3输出:(这不使我的问题的来源显而易见。)

 启动语法检查作为新行已被看到
flymake正在运行:nil
文件/Users/schof/pytest.py,init = flymake-pylint-init [3次]
create-temp-inplace:file = / Users / schof / pytest.py temp = / Users / schof / pytest_flymake.py
保存缓冲区pytest.py在文件/Users/schof/pytest_flymake.py
启动过程3221,command =(epylint pytest_flymake.py),dir = / Users / schof /
从进程3221收到704个字节的输出
文件/Users/schof/pytest.py,init = flymake-pylint-init
parsed'Trac eback(最近的最后一次呼叫):',no line-err-info
parse line:file-idx = 2 line-idx = 3 file = / Users / schof / py / scripts / epylint line = 4 text =在< module>
get-real-file-name:file-name = / Users / schof / py / scripts / epylint real-name =〜/ py / scripts / epylint
parsed'File/ Users / schof / py / scripts / epylint,第4行在< module>'中,得到了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
解析'文件'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py ,第2556行在< module>'中,得到了line-err-info
解析'working_set.require(__ requires__)',没有行-err-info
解析行: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
解析File/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py,第620行,需要,get-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 / Framework
解析'文件'/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py,行518,在解决',得到行错误信息
解析'raise DistributionNotFound(req)#XXX把更多的信息放在这里',没有line-err-info
解析'pkg_resources.DistributionNotFound:pylint == 0.23.0',no line-err-info
文件/Users/schof/pytest.py,init = flymake-pylint-init
进程3221退出与代码1
清理使用flymake-simple-cleanup
d文件/Users/schof/pytest_flymake.py
在(1-18)创建了一个覆盖图
pytest.py:4个错误,0个警告(0.47秒)

为了比较,这里是从emacs运行时的flymake verbosity 3的输出文本模式。 hello world文件通过所有pylint测试。

 启动语法检查作为新行已被看到
flymake正在运行:nil
文件/Users/schof/pytest.py,init = flymake-pylint-init [3次]
create-temp-inplace:file = / Users / schof / pytest.py temp = / Users / schof / pytest_flymake.py
保存缓冲区pytest.py在文件/Users/schof/pytest_flymake.py
启动进程3395,command =(epylint pytest_flymake.py),dir = / Users / schof /
文件/Users/schof/pytest.py,init = flymake-pylint-init
进程3395退出代码0
使用flymake-simple-cleanup清理
已删除的文件/Users/schof/pytest_flymake.py
pytest.py:0错误,0警告(秒)0.30秒)


解决方案

为了更清楚地看到发生了什么,增加flymake日志级别,然后查看 *消息*

 (setq flymake -log级3)

没有这个信息,我不会推测可能的问题。 / p>

有一个窍门来避免 environment.plist 方法,BTW;您可以让Emacs询问您的常规shell是否适用您的首选路径:

 (defun set-exec-path-from-shell- PATH()
(let((path-from-shell(replace-regexp-in-string
[\t\\\
] * $

(shell-command-to-string$ SHELL --login -i -c'echo $ PATH'))))
(setenvPATHfrom-shell)
(setq exec -path(split-string path-from-shell path-separator))))

(当(和window-system(eq system-type'darwin))
;;启动时从Emacs.app或类似的,确保$ PATH
;;是相同的用户将看到在Terminal.app
(set-exec-path-from-shell-PATH))

(从我的Emacs config ,其中包含一堆flymake代码,其中包括使用 pyflakes 的python配置,因此您可能需要查看。)



更新:现在你已经添加了详细的输出,我看到你的〜/ py / epylint程序找不到 pkg_resources ,它指向 PYTHONPATH 错误。所以,使用上述技术的变体,尝试这样:

 (defun setenv-from-shell(varname)
(setenv varname(replace-regexp-in-string
[\t\\\
] * $

(shell-command-to-string(concat$ SHELL --login -i -c'echo $varname')))))

(setenv-from-shellPYTHONPATH)


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) 

解决方案

To more clearly see what's going wrong, increase flymake's log level, then look in *messages*:

(setq flymake-log-level 3)

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:

(defun set-exec-path-from-shell-PATH ()
  (let ((path-from-shell (replace-regexp-in-string
                          "[ \t\n]*$"
                          ""
                          (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "PATH" path-from-shell)
    (setq exec-path (split-string path-from-shell path-separator))))

(when (and window-system (eq system-type 'darwin))
  ;; When started from Emacs.app or similar, ensure $PATH
  ;; is the same the user would see in Terminal.app
  (set-exec-path-from-shell-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 to PYTHONPATH being wrong. So, using a variation on the above technique, try this:

(defun setenv-from-shell (varname)
  (setenv varname (replace-regexp-in-string
                   "[ \t\n]*$"
                   ""
                   (shell-command-to-string (concat "$SHELL --login -i -c 'echo $" varname "'")))))

(setenv-from-shell "PYTHONPATH")

这篇关于Pylint不能在OS X上使用Emacs GUI;从命令行工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆