Windows 上 emacs 中的 pyflakes 问题
我点击了此链接此处尝试在 Windows 上为 python dev 设置 emacs。尽管一切看起来都很好,但 pyflakes 正在制造问题并且不给我语法检查。每次我打开“.py”文件时,都会收到错误 “无法使用参数'foo.py'启动语法检查进程'pyflakes':搜索程序:没有这样的文件或目录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)
I followed this link here to try and set up emacs for python dev on windows. Although everything seems fine, pyflakes is creating problems and not giving me the syntax checking. Everytime I open a '.py' file, I get the error
"Failed to launch syntax check process 'pyflakes' with args 'foo.py': searching for program: No such file or directory pyflakes"
Could anyone please help me with this?
Update:
Here is my .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")
And here is my 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
终于可以工作了!
感谢菲尔斯为我指明了正确的方向。经过谷歌搜索后,找到了这个,并在谷歌翻译的帮助下(该页面是俄语)终于能够让语法检查工作了!
英文详细信息:
按照常规方式安装 pyflakes 后,执行以下操作:
使用以下代码在
_YourPythonRootDir_\Scripts
中创建名为runpyflakes.py
的文件:>
在
中创建名为“pyflakes.bat”的文件>_YourPythonRootDir_\Scripts
包含以下行:添加
_YourPythonRootDir_\Scripts
添加到“Path”环境变量问题已解决!
注意:
_YourPythonRootDir_
=系统上 Python 根目录的路径。在我的中,它是C:\Python26\
当然感谢 Phils、Starkey 和 gelvaos!
Got it to work finally!
Thanks to phils for pointing me in the right direction. After googling, found this and with the help of google translator (The page is in Russian) was able to finally get syntax checking to work!
Details in english:
After installing pyflakes the usual way, do the following:
Create file called
runpyflakes.py
in_YourPythonRootDir_\Scripts
with the following code:Create file called "pyflakes.bat" in
_YourPythonRootDir_\Scripts
with the following lines:Add
_YourPythonRootDir_\Scripts
to the "Path" environment variablePROBLEM SOLVED!!!
Note:
_YourPythonRootDir_
=path to Python's root directory on your system. In mine itsC:\Python26\
Thanks Phils,Starkey, and gelvaos of course!!!
如果您按照这些说明使用 apt-get 那么我不认为这是权限问题*,所以听起来 emacs 只是看不到可执行文件。
Flymake 调用
start-process
在exec-path
目录中查找程序 (Chvexec-path
RET)您可以在 .emacs 中添加类似
(add-to-list 'exec-path "~/bin")
的内容来使相应的目录可见。(*) 如果您没有使用包管理器 OTOH 安装它,那么我也会检查权限。
If you used apt-get as in those instructions then I don't imagine it's a permission issue*, so it sounds like emacs just can't see the executable.
flymake calls
start-process
which looks for the program in theexec-path
directories (C-hvexec-path
RET)You can put something like
(add-to-list 'exec-path "~/bin")
in your .emacs to make the appropriate directory visible.(*) If you didn't install it with a package manager, OTOH, then I would also check permissions.