Emacs:即使已安装`virtualenv`,`jedi:install-server`也会失败

时间:2020-02-29 16:20:34

标签: python emacs

我正在尝试根据this manual为Emacs安装JEDI自动完成功能。

输入M-x jedi:install-server时,出现错误Program named "virtualenv" does not exist。我遵循了this answer中的建议,并使用pip install virtualenv进行了安装。现在,当我在终端中输入virtualenv时,将得到以下输出:

usage: virtualenv [--version] [--with-traceback] [-v | -q] [--app-data APP_DATA] [--clear-app-data] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed]
                  [--activators comma_sep_list] [--clear] [--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip]
                  [--no-setuptools] [--no-wheel] [--symlink-app-data] [--prompt prompt] [-h]
                  dest
virtualenv: error: the following arguments are required: dest

然后我重新启动,输入了M-x jedi:install-server,但仍然出现相同的错误。

我正在Linux Mint 19.3 Tricia上使用2019-12-03的GNU Emacs 26.3(内部版本1,x86_64-pc-linux-gnu,GTK +版本3.22.30)。

如何解决此错误并开始使用JEDI自动补全功能?

更新1:另外,每当我打开Python文件时,都会收到此警告

*** EPC Server Config ***
Server arguments: ("/usr/bin/python" "/home/XXXXXXX/.emacs.d/elpa/jedi-core-20191011.1750/jediepcserver.py")
Actual command: /usr/bin/python
VIRTUAL_ENV envvar: nil

*** jedi-mode is disabled in #<buffer createPageStructure.py> ***
Fix the problem and re-enable it.

*** You may need to run "M-x jedi:install-server". ***
This could solve the problem especially if you haven't run the command yet
since Jedi.el installation or update and if the server complains about
Python module imports.

3 个答案:

答案 0 :(得分:2)

我有一个类似的问题,我也在使用Linux Mint Tricia。我想使用company-jedi代替jedi-ac

就我而言,我想让jedi和emacs使用python3.8。所以我想要基于python3.8的jedi virtualenv。

Jedi virtualenv是使用emacs-python-enviroment软件包创建的。

我的问题似乎来自于emacs-python-enviroment默认使用选项'--system-site-package'的事实,所以我遇到了很多错误,因为系统python3是python3.6,而我不要(而且我不想)在系统范围的python3中安装所有需要的软件包。

我解决了在emacs-python-enviroment中添加选项'--no-site-package'(参见this)的问题

emacs-python-enviroment用于创建名为'default'的jedi virtualenv,位于'〜/ .emacs.d / .python-enviroments /'中,如果您要配置此virtualenv的其他名称和位置,则可以想要(有关更多信息,请参见this

这是我的工作配置。您可以指定一个不同的python而不是python3.8(我使用的那个)

 (setq python-shell-interpreter "/usr/bin/python3.8")
 (setq py-python-command "/usr/bin/python3.8")        ; maybe not needed
 (setq python-python-command "/usr/bin/python3.8")    ; maybe not needed

 (use-package company-jedi             ;;; company-mode completion back-end for Python JEDI
   :ensure t
   :config
   (setq jedi:environment-virtualenv
         (append python-environment-virtualenv
                 '("--no-site-packages" "--python" "/usr/bin/python3.8")))
   ;;(setq jedi:environment-virtualenv (list (expand-file-name "~/.emacs.d/.python-environments/")))
   (add-hook 'python-mode-hook 'jedi:setup)
   (setq jedi:complete-on-dot t)
   (setq jedi:use-shortcuts t)
   (defun config/enable-company-jedi ()
     (add-to-list 'company-backends 'company-jedi))
   (add-hook 'python-mode-hook 'config/enable-company-jedi)
   )

答案 1 :(得分:1)

我不再使用jedi并已切换到lsp-mode,但是下面是我使用company-jedi来完成Python的旧工作配置。加载python-mode时,如果尚未安装jedi支持,它将调用jedi:install-server-block来安装jedi支持。您可能要检查*Messages*缓冲区以查看是否打印出Installing jedi server...。希望这会有所帮助。

(use-package company-jedi
  :if (executable-find "virtualenv")
  :ensure t
  :bind
  (:map python-mode-map
        ("M-." . jedi:goto-definition)
        ("M-," . jedi:goto-definition-pop-marker))
  :config
  (unless (file-exists-p
           (expand-file-name
            ".python-environments" user-emacs-directory))
    (message "Installing jedi server...")
    (jedi:install-server-block)
    (message "Installing jedi server...done"))
  :hook
  (python-mode
   . (lambda ()
       (setq-local company-backends
                   (append (list 'company-jedi) company-backends)))))

答案 2 :(得分:1)

以这种方式将上面警告中显示的“服务器参数”添加到 .emacs 文件中。

(setq jedi:server-command ("/usr/bin/python" "/home/XXXXXXX/.emacs.d/elpa/jedi-core-20191011.1750/jediepcserver.py"))