2011-04-04 18 views
4

當從命令行運行(emacs filename.py)時,flymake和pylint可以很好地協同工作。錯誤被正確突出顯示。 (雖然我無法提示懸停以獲取錯誤細節,因爲它是文本模式。)Pylint不能在OS X上使用Emacs GUI;從命令行運行

從GUI(Carbon Emacs)運行時,Flymake立即返回,並且文件中的第一行突出顯示錯誤「in <module> 」。第一行顯示錯誤,即使在「Hello World」腳本中。)我想在GUI模式下正常工作,以便我可以用鼠標導航(我知道,我知道)並使用工具提示獲取詳細信息在pylint上報告錯誤。

我用「easy_install pylint」安裝了pylint,並且pylint和epylint腳本位於「~/py/scripts」中。我添加了目錄,是我路上在我的.bashrc:

export PATH=$PATH:~/py/scripts 

(我的.profile文件是一個符號鏈接到我的.bashrc)

我意識到,Emacs的圖形用戶界面並沒有從我的加載路徑。因此我創建了一個〜/ .MacOSX/environment.plist文件,並使用我在終端中看到的完整路徑設置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" 

同樣, 「C-h 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大師,所以我可能在這裏錯過了一些明顯的東西;隨時索取更多細節。

OS X 10.6.7;碳Emacs 22.3.1; pylint 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的回答是:

詳細級別3輸出flymake的*messages*:(這確實沒有使問題的根源對我來說是顯而易見的。)

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) 

爲了比較,這裏是flymake verbosit的輸出y 3從emacs運行時文本模式。 「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) 
+0

完整的錯誤會有所幫助。它看起來像flymake *正在運行,否則你可能不會得到一個「在」錯誤。我的猜測是你的'PYTHONPATH'在終端和GUI上是不同的。我也很驚訝'.MacOSX /環境'技巧的作品。你在運行雪豹嗎? – milkypostman 2011-04-05 18:37:58

+0

是的,雪豹10.6.7。 – Schof 2011-04-06 03:24:16

+0

離開城市而無法上網(沒想到這需要很長時間才能解決)。將於4月11日回覆並回復其他問題/測試建議。 – Schof 2011-04-06 07:03:31

回答

2

爲了更清楚地看到發生了什麼錯誤,提高flymake的日誌級別,然後查看*messages*

(setq flymake-log-level 3) 

沒有這些信息,我不會對可能出現的問題猜測。

避免採用environment.plist的方法有一招,順便說一句,你可以得到的Emacs詢問你的常規外殼爲您的首選路徑:

(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)) 

(這是從my Emacs config,裏面有一堆在它flymake代碼,包括使用pyflakes蟒蛇一個配置解除,所以你可能要看看)

更新:現在你已經添加了詳細的輸出,我看到你的〜/ PY/epylint程序無法找到pkg_resources,它指向PYTHONPATH是錯誤的。因此,使用上述技術的變體,試試這個:

(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") 
+0

我使用您請求的詳細日誌記錄輸出編輯了我的問題。我還將您的建議.emacs PATH想法添加到我的.emacs中,但症狀沒有任何變化。 – Schof 2011-04-06 07:02:27

+0

我加了一些其他的東西,你可以嘗試我的答案。 – sanityinc 2011-04-06 07:30:05

+0

工作就像一個魅力,Sanityinc!謝謝! – Schof 2011-04-23 03:25:25

相關問題