Python3, Elpy in Emacs (OSX): No completion found user-error: Cannot complete at point

Python3, Elpy in Emacs (OSX): No completion found user-error: Cannot complete at point

OSX 10.13.4 emacs:25.3 (9.0) python3.5.2

我可能在使用 emcas 中的 elpy 自动完成时遇到问题。本质上,elpy 卡在点上(例如:numpy.)并且不建议任何可能的完成。如果我按任意键,我会看到一条消息:“未找到完成 用户错误:尽管已正确安装所有必需的软件包,但无法在该点完成。我怀疑这可能是由于配置造成的:

Elpy Configuration

Virtualenv........: None
RPC Python........: 3.5.2 (/usr/local/bin/python3)
Interactive Python: /usr/local/bin/python3 (/usr/local/bin/python3)
Emacs.............: 25.3.1
Elpy..............: 1.19.0
Jedi..............: 0.12.0
Rope..............: 0.10.7
Autopep8..........: 1.3.5
Yapf..............: 0.21.0
Syntax checker....: Not found (flake8)

You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.

The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH -- and then do
`elpy-rpc-restart'.

The configured syntax checker could not be found. Elpy uses this
program to provide syntax checks of your programs, so you might want
to install one. Elpy by default uses flake8.

但是,当尝试在终端中设置路径时:'PATH=$PATH:/.local/bin/' 确实解决了问题。

请问我该如何解决这个问题?

解决此问题的最简单方法是使用:https://github.com/purcell/exec-path-from-shell 包。它将在 Emacs 中设置路径来解决您的问题。如果您不想安装此软件包,可以将以下代码片段放入 .emacs.

(let ((path (shell-command-to-string "$SHELL -cl \"printf %s \\"\$PATH\\"\"")))
  (setenv "PATH" path)
  (setq exec-path (split-string path path-separator)))

以上内容适用于任何 shell 兼容的 sh。我建议使用 exec-path-from-shell 易于设置,并且无论您使用什么 shell 都可以正常工作。

请记住,这两种方法都会从 shell 中获取 $PATH,因此请确保您的 PATH$HOME/.bashrc 中按照您的需要进行设置假设您使用的是 bash。类似于:export PATH=$HOME/.local/bin:$PATH 应该这样做。