pymacs:常见问题及安装问题

6 投票
3 回答
5296 浏览
提问于 2025-04-15 12:39

我正在尝试为Python开发设置Emacs。

根据我了解到的信息,推荐使用python-mode.el,而不是Emacs 22.3自带的默认python.el。所以我决定开始这个新冒险。

我明白python-mode有几个依赖项,所以我需要安装rope、ropemode和ropemacs。除此之外,我还需要安装pymacs。

问:这样做对吗?

这是我现在的新.emacs配置:

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t)
 '(tab-width 4))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )

(setq emacs-config-path "~/.emacs.d/")
(setq base-lisp-path "~/.emacs.d/site-lisp/")
(setq site-lisp-path (concat emacs-config-path "/site-lisp"))
(defun add-path (p)
  (add-to-list 'load-path (concat base-lisp-path p)))

(add-path "") 
(add-to-list 'load-path "~/.emacs.d")

(require 'psvn)

;; python-mode
;;
(setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)


(setq pymacs-load-path '(   "~/.emacs.d/site-lisp/rope"
                            "~/.emacs.d/site-lisp/ropemode"
                            "~/.emacs.d/site-lisp/ropemacs"))


(setq interpreter-mode-alist
      (cons '("python" . python-mode)
        interpreter-mode-alist)
      python-mode-hook
      '(lambda () (progn
            (set-variable 'py-indent-offset 4)
            (set-variable 'py-smart-indentation nil)
            (set-variable 'indent-tabs-mode nil)
            ;;(highlight-beyond-fill-column)
                    (define-key python-mode-map "\C-m" 'newline-and-indent)
            (pabbrev-mode)
            (abbrev-mode)
     )
      )
)


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

;; Search local path for emacs rope
;;

;; enable pymacs
;; 
(require 'pymacs)
(pymacs-load "ropemacs" "rope-")

现在,当我启动Emacs时,出现了这个错误信息:

("C:\\opt\\emacs-22.3\\bin\\emacs.exe")
Loading encoded-kb...done
Loading regexp-opt...done
Loading easy-mmode...done
Loading wid-edit...done
Loading edmacro...done
Loading derived...done
Loading advice...done
Loading cl-macs...done
Loading byte-opt...done


An error has occurred while loading `c:/opt/cygwin/home/akong/.emacs':

File error: Cannot open load file, pymacs

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

For information about GNU Emacs and the GNU system, type C-h C-a. [2 times]

为了让事情稍微复杂一点:

因为工作原因,我必须使用Python 2.4,但我电脑上安装的是Python 2.6。显然,rope不支持2.4,所以我没有运行setup.py。我解压了这些包,并把这些文件放在了~/.emacs.d/site-lisp目录下。默认情况下,如果在命令提示符下调用Python,执行的是Python 2.4的可执行文件。

问:我该如何成功加载'pymacs'?

3 个回答

1

如果路径缺失,这个问题在启动日志中很容易就能发现,或者在启动Emacs时获取回溯信息也能看到。如果不确定,可以使用M-x load-library这个命令来解决。

我也遇到了company-ropemacs在最新的Debian Testing更新后,在Emacs 23和Emacs 24中都无法加载的问题,这样就导致你无法保存文件,因为有个叫做rope的保存钩子。我很想知道有没有人能让它正常工作。总的来说,company-ropemacs和Emacs中的Python一直以来都是个麻烦。我打算稍后再尝试调试这个问题,到时候会更新这个讨论。

1

我之前从来没有用过pymacs,不过当我看到你的.emacs文件时,有一点引起了我的注意:你似乎没有把pymacs的目录添加到emacsload-path中,而只是添加到了pymacs的路径里。

(setq pymacs-load-path '( "~/.emacs.d/site-lisp/rope"
                          "~/.emacs.d/site-lisp/ropemode"
                          "~/.emacs.d/site-lisp/ropemacs"))

你可能还需要添加类似下面的内容:

(add-to-list 'load-path "~/.emacs.d/site-lisp/rope")
(add-to-list 'load-path "~/.emacs.d/site-lisp/ropemode")
(add-to-list 'load-path "~/.emacs.d/site-lisp/ropemacs")

(或者在你放置pymacs.el的地方),这样emacs才能找到这些lisp文件。这个内容在pymacs的文档中也有提到。

2.4 正确安装Pymacs ... 关于Emacs的部分 ...

现在通常是手动完成的。首先选择Emacs的load-path列表中的某个目录,确保你有写入权限,然后把文件pymacs.el复制到那个目录里。

1

结果我发现我漏掉了这两个:

(add-to-list 'load-path "~/.emacs.d/site-lisp/Pymacs-0.23")

显然我需要加载pymac脚本。

而且我把环境变量PYMACS_PYTHON设置成了python 2.6,因为我默认使用的python解释器是python 2.4,这是出于工作的需要。

撰写回答