Spacemacs中python不能补全

emacs小白求助,mac已经用pip安装了anaconda-mode,安装没有任何异常。可是在spacemacs中python mode怎么也不能使用python补全。也没有anaconda-mode的buffer。

启动REPL,好像只是auto-complete的backend起作用了: Shell native completion is enabled. Company: An error occurred in auto-begin Company: backend (company-files company-capf) error “Invalid search bound (wrong side of point)” with args (prefix)

觉得是安装的anaconda-mode并没有北spacemacs用到。不知道为啥了,求助各位。已经看了相应的帖子,没有太大帮助。

我在home目录下的.emacs.d目录下也没有找到anaconda-mode目录。但是在spacemacs里查看anaconda-mode package已经安装了,实在不知道为什么

正常情况下应该不会用到 pip。 感觉是你安装的方法不对。

我是按照官方的python layer弄的,理解错了安装方式,在shell命令行用pip安装了anaconda-mode。

但是我用M-x查看spacemacs安装的包的时候,看到anaconda-mode已经安装了。这个anaconda-mode正确的安装方式是什么呢?

你可以看一下这个包的安装路径在哪里。

对Emacs来说只要指定了路径,插件不管保存在哪里都可安装。

不贴出错信息的提问都是耍流氓

https://github.com/proofit404/anaconda-mode#usage 已经写明了补全的几种方法:

  • 按快捷键 C-M-i 手动补全
  • 通过 company-modeauto-complete-mode 自动补全

没起作用的原因有可能:

  • anaconda-mode (包括 company-mode/auto-complete-mode) 没有启用
  • anaconda-mode-server 没有安装/启动

而 anaconda-mode-server 在首次触发补全的时候会自动安装,安装位置就在 ~/.emacs.d/

anaconda-mode包在.emacs.d/elpa/anaconda-mode-20170405.301这个目录下。

看了Message buffer。没有关于anaconda-mode的任何报错,也没有anaconda-mode buffer。唯一一个报错就是打开python文件的时候有个这个消息: File mode specification error: (file-error Cannot open load file No such file or directory yasnippet)

其他任何报错都没有。启动REPL,输入几行python code, Message buffer里给出的信息是: Shell native completion is enabled Company: An error occurred in auto-begin Company: backend (company-files company-capf) error “Invalid search bound (wrong side of point)” with args (prefix)

我用M-x package-list-packages,显示只有anaconda-mode有安装,没有看到anaconda-mode-server

你应该打开 debug 模式 SPC t D,报错以后,把错误信息贴过来

打开一个project里的python文件,报错是这个:

Debugger entered--Lisp error: (file-error "Cannot open load file" "No such file or directory" "yasnippet")
  (yas-global-mode 1)
  (if yas-global-mode nil (yas-global-mode 1))
  spacemacs/load-yasnippet()
  run-hooks(change-major-mode-after-body-hook prog-mode-hook python-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook python-mode-hook))
  run-mode-hooks(python-mode-hook)
  python-mode()
  set-auto-mode-0(python-mode nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer app.py> "~/Documents/Workspaces/flask/flask/app.py" nil nil "~/Documents/Workspaces/flask/flask/app.py" (39515434 16777220))
  find-file-noselect("/Users/shu/Documents/Workspaces/flask/flask/app.py" nil nil nil)
  find-file("/Users/shu/Documents/Workspaces/flask/flask/app.py")
  find-file-at-point("/Users/shu/Documents/Workspaces/flask/flask/app.py")
  #[257 "\306\307\310\"\205\f\311\"	\312\313\310eA\2033
\203%\314\312\"\202}\315\316A\"\210\[email protected]!\202}\320!\204N\204N\311\321a\"\203N\211\322\"\202}?\205W\323!\324\203i\325!\203i\326!\202z\203ra\202z!\205za!\262+\207" [ffap-url-regexp helm-ff-newfile-prompt-p helm--reading-passwd-or-string find-file-wildcards ffap-newfile-prompt helm-current-prefix-arg helm-marked-candidates :with-wildcard t string-match nil #[513 "\203
\303\304\305\"!\205=\306!\307!\203 \310\311\312!\"\210\202%\313\314\"\210\210\211\2032\315!\211\nB\211\203<\316!\206=\317\207" [confirm-nonexistent-file-or-buffer helm-ff-default-directory helm-ff-history y-or-n-p format "Create directory `%s'? " directory-file-name file-exists-p error "Mkdir: Unable to create directory `%s': file exists." helm-basename make-directory parent file-name-as-directory helm-find-files-1 t] 8 "\n\n(fn DIR &optional HELM-FF)"] dired-simultaneous-find-file mapc find-file-noselect find-file file-exists-p "/$" helm-ff helm-basedir find-file-at-point file-directory-p substitute-in-file-name] 10 ("/Users/shu/.emacs.d/elpa/helm-20170409.26/helm-files.elc" . 108895)]("/Users/shu/Documents/Workspaces/flask/flask/app.py")
  apply(#[257 "\306\307\310\"\205\f\311\"	\312\313\310eA\2033
\203%\314\312\"\202}\315\316A\"\210\[email protected]!\202}\320!\204N\204N\311\321a\"\203N\211\322\"\202}?\205W\323!\324\203i\325!\203i\326!\202z\203ra\202z!\205za!\262+\207" [ffap-url-regexp helm-ff-newfile-prompt-p helm--reading-passwd-or-string find-file-wildcards ffap-newfile-prompt helm-current-prefix-arg helm-marked-candidates :with-wildcard t string-match nil #[513 "\203
\303\304\305\"!\205=\306!\307!\203 \310\311\312!\"\210\202%\313\314\"\210\210\211\2032\315!\211\nB\211\203<\316!\206=\317\207" [confirm-nonexistent-file-or-buffer helm-ff-default-directory helm-ff-history y-or-n-p format "Create directory `%s'? " directory-file-name file-exists-p error "Mkdir: Unable to create directory `%s': file exists." helm-basename make-directory parent file-name-as-directory helm-find-files-1 t] 8 "\n\n(fn DIR &optional HELM-FF)"] dired-simultaneous-find-file mapc find-file-noselect find-file file-exists-p "/$" helm-ff helm-basedir find-file-at-point file-directory-p substitute-in-file-name] 10 ("/Users/shu/.emacs.d/elpa/helm-20170409.26/helm-files.elc" . 108895)] "/Users/shu/Documents/Workspaces/flask/flask/app.py")
  helm-find-file-or-marked("/Users/shu/Documents/Workspaces/flask/flask/app.py")
  helm-execute-selection-action-1()
  helm-execute-selection-action()
  helm-internal((helm-source-projectile-buffers-list helm-source-projectile-files-list helm-source-projectile-projects) nil "[flask] pattern: " nil nil "*helm projectile*" nil nil nil)
  apply(helm-internal ((helm-source-projectile-buffers-list helm-source-projectile-files-list helm-source-projectile-projects) nil "[flask] pattern: " nil nil "*helm projectile*" nil nil nil))
  helm((helm-source-projectile-buffers-list helm-source-projectile-files-list helm-source-projectile-projects) nil "[flask] pattern: " nil nil "*helm projectile*" nil nil nil)
  apply(helm ((helm-source-projectile-buffers-list helm-source-projectile-files-list helm-source-projectile-projects) nil "[flask] pattern: " nil nil "*helm projectile*" nil nil nil))
  helm(:sources (helm-source-projectile-buffers-list helm-source-projectile-files-list helm-source-projectile-projects) :buffer "*helm projectile*" :truncate-lines nil :prompt "[flask] pattern: ")
  helm-projectile()
  projectile-switch-project-by-name("~/Documents/Workspaces/flask/")
  #[257 "\301\302!)\207" [projectile-completion-system helm projectile-switch-project-by-name] 3 "\n\n(fn PROJECT)"]("~/Documents/Workspaces/flask/")
  helm-execute-selection-action-1()
  helm-execute-selection-action()
  helm-internal(helm-source-projectile-projects nil "[-] Switch to project: " nil nil "*helm projectile*" nil nil nil)
  apply(helm-internal (helm-source-projectile-projects nil "[-] Switch to project: " nil nil "*helm projectile*" nil nil nil))
  helm(helm-source-projectile-projects nil "[-] Switch to project: " nil nil "*helm projectile*" nil nil nil)
  apply(helm (helm-source-projectile-projects nil "[-] Switch to project: " nil nil "*helm projectile*" nil nil nil))
  helm(:sources helm-source-projectile-projects :buffer "*helm projectile*" :truncate-lines nil :prompt "[-] Switch to project: ")
  helm-projectile-switch-project(nil)
  funcall-interactively(helm-projectile-switch-project nil)
  call-interactively(helm-projectile-switch-project nil nil)
  command-execute(helm-projectile-switch-project)

看你的回复我很捉急,根本不在点上。你一直强调 anaconda-mode 已经安装,但是没有去确认是不是已经启用。

anaconda-mode-server 是为 anaconda-mode 提供补全的后台服务。anaconda-mode 启用之后,在首次使用补全的时候会自动安装。

你要做的是:

  • 启用 anaconda-mode
  • 触发补全,最简单就是手动调用一下 M-x anaconda-mode-complete

观察到底是在哪个步骤出错

不好意思。按照你说的,启用了anaconda-mode,然后现在在.emacs.d目录下也有anaconda-mode目录了。 在anaconda-mode buffer里只有一条信息: anaconda_mode port 49861

但是在python文件里按TAB还是不见自动补全的popup list。

Python layer官方文档里说的这个自动启动anaconda-mode,这行加在哪里呢? You can automatically enable anaconda-mode in all python buffers with following code in your configuration:

(add-hook 'python-mode-hook 'anaconda-mode)

user-config 就行了。

我不清楚 Python layer (你也没给链接)。

anaconda-mode 本身并不具备自动补全,需要 company-anaconda 和 auto-complete-mode 配合,在 https://github.com/proofit404/anaconda-mode#usage 里有说明。

你现在 sever 已经启动了,就不要再纠结 TAB,先手动验证一下 M-x anaconda-mode-complete 是否会补全。然后再考虑自动补全。

非常感谢。手动M-x anaconda-mode-complete是可以补全的。现在就看怎么能自动补全了。

非常感谢。我试试。

我之前遇到不能自动补全的原因是没有把auto-completion layer加上