2010-08-18 74 views
3

我跟隨此鏈接here嘗試在Windows上爲python dev設置emacs。雖然一切看起來都很好,但pyflakes正在產生問題,並沒有給我語法檢查。每次我打開一個'.py'文件,我得到錯誤 「無法啓動語法檢查過程'pyflakes'與args'foo.py':搜索程序:沒有這樣的文件或目錄pyflakes」Windows上的emacs中的pyflakes問題

任何人都可以請在這件事上給予我幫助?

更新:

這裏是我的.emacs

;; Abhi's c:\.emacs file 


(add-to-list 'load-path "C:/emacs/colors/") 
(require 'color-theme) 
(eval-after-load "color-theme" 
    '(progn 
    (color-theme-initialize) 
    (color-theme-charcoal-black))) 

(set-default-font "-outline-Monaco-normal-r-normal-normal-13-97-96-96-c-*-iso8859-1") 

;Mappings to zoom in and out 
(defun sacha/increase-font-size() 
    (interactive) 
    (set-face-attribute 'default 
         (selected-frame) 
         :height 
         (ceiling (* 1.10 
            (face-attribute 'default :height))))) 
(defun sacha/decrease-font-size() 
    (interactive) 
    (set-face-attribute 'default 
         nil 
         :height 
         (floor (* 0.9 
            (face-attribute 'default :height))))) 
(global-set-key (kbd "C-+") 'sacha/increase-font-size) 
(global-set-key (kbd "C--") 'sacha/decrease-font-size) 

;muse mode mappings 
(add-to-list 'load-path "C:/emacs/Muse/muse-latest/lisp/") 

(require 'muse-mode) 
(require 'muse-latex) 
(require 'muse-book) 
(require 'muse-html) 
(require 'muse-colors) 


;To do list mode config 
(add-to-list 'load-path "C:/emacs/lisp/") 
(autoload 'todo-list-mode "todo-list-mode") ;load when needed 

;a simple function that opens the file, 
;and switches to todo-list-mode. 
(defun open-todo-list() 
    (interactive) 
    (find-file "D:/AbhisLife/Tasks/TODO") 
    (todo-list-mode)) 

;then bind to control-f12 so i can call it with one keystroke 
;this works well for me because i also bind calendar to f12 
(global-set-key [C-f12] 'open-todo-list) 

;Python development 
(require 'smart-operator) 
(add-to-list 'load-path "~/.emacs.d/") 
(require 'yasnippet) 
(yas/initialize) 
(yas/load-directory "~/.emacs.d/snippets/") 
(require 'auto-complete) 
(global-auto-complete-mode t) 
;(require 'init-auto-complete) 
(load-library "init_python") 

這裏是我的init_python.el

(autoload 'python-mode "python-mode" "Python Mode." t) 
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) 
(add-to-list 'interpreter-mode-alist '("python" . python-mode)) 
(require 'python-mode) 


(add-hook 'python-mode-hook 
     (lambda() 
    (set-variable 'py-indent-offset 4) 
    ;(set-variable 'py-smart-indentation nil) 
    (set-variable 'indent-tabs-mode nil) 
    (define-key py-mode-map (kbd "RET") 'newline-and-indent) 
    ;(define-key py-mode-map [tab] 'yas/expand) 
    ;(setq yas/after-exit-snippet-hook 'indent-according-to-mode) 
    (smart-operator-mode-on) 
    )) 
;; pymacs 
(autoload 'pymacs-apply "pymacs") 
(autoload 'pymacs-call "pymacs") 
(autoload 'pymacs-eval "pymacs" nil t) 
(autoload 'pymacs-exec "pymacs" nil t) 
(autoload 'pymacs-load "pymacs" nil t) 
;(eval-after-load "pymacs" 
; (add-to-list 'pymacs-load-path "C:/Python26/MyDownloads/Pymacs/")) 
(pymacs-load "ropemacs" "rope-") 
(setq ropemacs-enable-autoimport t) 


;(setq yas/trigger-key (kbd "C-c <kp-multiply>")) 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;; Auto-completion 
;;; Integrates: 
;;; 1) Rope 
;;; 2) Yasnippet 
;;; all with AutoComplete.el 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
(defun prefix-list-elements (list prefix) 
    (let (value) 
    (nreverse 
    (dolist (element list value) 
     (setq value (cons (format "%s%s" prefix element) value)))))) 
(defvar ac-source-rope 
    '((candidates 
    . (lambda() 
    (prefix-list-elements (rope-completions) ac-target)))) 
    "Source for Rope") 
(defun ac-python-find() 
    "Python `ac-find-function'." 
    (require 'thingatpt) 
    (let ((symbol (car-safe (bounds-of-thing-at-point 'symbol)))) 
    (if (null symbol) 
    (if (string= "." (buffer-substring (- (point) 1) (point))) 
     (point) 
     nil) 
     symbol))) 
(defun ac-python-candidate() 
    "Python `ac-candidates-function'" 
    (let (candidates) 
    (dolist (source ac-sources) 
     (if (symbolp source) 
     (setq source (symbol-value source))) 
     (let* ((ac-limit (or (cdr-safe (assq 'limit source)) ac-limit)) 
     (requires (cdr-safe (assq 'requires source))) 
     cand) 
    (if (or (null requires) 
     (>= (length ac-target) requires)) 
     (setq cand 
      (delq nil 
      (mapcar (lambda (candidate) 
        (propertize candidate 'source source)) 
       (funcall (cdr (assq 'candidates source))))))) 
    (if (and (> ac-limit 1) 
     (> (length cand) ac-limit)) 
     (setcdr (nthcdr (1- ac-limit) cand) nil)) 
    (setq candidates (append candidates cand)))) 
    (delete-dups candidates))) 
(add-hook 'python-mode-hook 
     (lambda() 
     (auto-complete-mode 1) 
     (set (make-local-variable 'ac-sources) 
       (append ac-sources '(ac-source-rope))) 
     (set (make-local-variable 'ac-find-function) 'ac-python-find) 
     (set (make-local-variable 'ac-candidate-function) 'ac-python-candidate) 
     (set (make-local-variable 'ac-auto-start) nil))) 
;;Ryan's python specific tab completion 
(defun ryan-python-tab() 
    ; Try the following: 
    ; 1) Do a yasnippet expansion 
    ; 2) Do a Rope code completion 
    ; 3) Do an indent 
    (interactive) 
    (if (eql (ac-start) 0) 
     (indent-for-tab-command))) 
(defadvice ac-start (before advice-turn-on-auto-start activate) 
    (set (make-local-variable 'ac-auto-start) t)) 
(defadvice ac-cleanup (after advice-turn-off-auto-start activate) 
    (set (make-local-variable 'ac-auto-start) nil)) 
(define-key py-mode-map "\t" 'ryan-python-tab) 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;;; End Auto Completion 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;; Auto Syntax Error Hightlight 
;(require 'flymake) 

;;===== PyFlakes 
;; code checking via pyflakes+flymake 
;(load-file "C:/.emacs.d/flymake-cursor.el") 

;Commented because this is giving mea problem 


;(when (load "flymake" t) 
; (defun flymake-pyflakes-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 "pyflakes" (list local-file)))) 
; (add-to-list 'flymake-allowed-file-name-masks 
;   '("\\.py\\'" flymake-pyflakes-init))) 
;(add-hook 'find-file-hook 'flymake-find-file-hook) 
; 
;(provide 'init_python) 
+0

你可能在你的.emacs中犯了一個錯誤。這些說明有很多修改。也許你應該重新檢查一下,確保你的修改中的一切都正確。否則,發佈您的.emacs,也許我們可以找到一個錯誤。 – Starkey 2010-08-18 15:57:03

回答

2

如果使用apt-get的在這些說明,然後我不t想象這是一個許可問題*,所以它聽起來像emacs只是看不到可執行文件。

flymake調用start-process看起來在exec-path目錄的程序(C-Hvexec-pathRET

你可以把類似(add-to-list 'exec-path "~/bin")在你的.emacs做出相應的目錄中可見。

(*)如果你沒有安裝包管理器,OTOH,那麼我也會檢查權限。

+0

我實際上是在windows上工作,所以我下載了PyFlakes併爲pyflakes安裝了python setup.py。我試圖做你的東西,但它似乎並沒有工作。 – Abhi 2010-08-19 07:48:52

+0

對不起,只要我遵循以Ubuntu爲中心的鏈接,我一定已經清除了我腦中的Windows位。它仍然聽起來像一個路徑問題。什麼是你的emacs exec-path? pyflakes安裝在哪裏?你可以在emacs之外成功運行pyflakes嗎?特別是,你可以將它作爲「pyflakes」來運行,還是需要Windows的擴展才能使用它? (可能是一個pyflakes.bat或.cmd文件?) – phils 2010-08-19 10:21:02

+0

實際上,我無法像命令提示符那樣運行pyflakes。也許這是問題。我已經安裝pyflakes justtt like rope,並且包文件位於 pythonrootdir \ Lib \ site-packages \ pyflakes 這是對的嗎?我應該在哪裏安裝pyflakes。我讀了一些地方,我們必須設置路徑環境變量與pyflakes exe的路徑。如果是,我將它映射到哪個文件夾?有任何想法嗎?我的emacs exec路徑我感覺很好,因爲其他人喜歡繩子工作正常。 – Abhi 2010-08-19 14:07:17

5

終於搞定了!

感謝phils指引我在正確的方向。谷歌搜索後,發現this和谷歌翻譯的幫助(該網頁是俄語)能夠最終得到語法檢查工作!

詳細的英文:

安裝pyflakes通常的方式後,請執行下列操作:

  1. 創建文件稱爲_YourPythonRootDir_\Scriptsrunpyflakes.py用下面的代碼:

    from pyflakes.scripts.pyflakes import main 
    main()
  2. 創建文件在_YourPythonRootDir_\Scripts中用以下行稱爲「pyflakes.bat」:

    @_YourPythonRootDir_\python.exe _YourPythonRootDir_\Scripts\runpyflakes.py %*
  3. 添加_YourPythonRootDir_\Scripts的 「路徑」 環境變量

問題解決了!

注意:_YourPythonRootDir_ =系統上Python根目錄的路徑。在我的C:\Python26\

謝謝Phils,Starkey和gelvaos!

+0

這裏只是一個小東西,從pyflakes.scripts.pyflakes import main main()中讀取的文本應該在前面的文本之前的行上有main(),也就是說,在main()之前應該有一個換行符。 – glaucon 2010-12-06 01:35:58