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

标签 python emacs

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

当我输入 M-x jedi:install-server 时,收到错误名为“virtualenv”的程序不存在。我遵循了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 月 3 日的 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.

最佳答案

我也有类似的问题,我也在使用 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 用于创建 jedi virtualenv,名为“default”并位于“~/.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)
   )

关于python - Emacs:即使安装了 `jedi:install-server`, `virtualenv` 也会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60467212/

相关文章:

emacs - 我怎么知道我是在 .emacs 文件中运行 emacs 还是 aquamacs?

emacs - 按住 Shift 时,用于移动的键绑定(bind)不会扩展区域

emacs - 我可以将 swank-clojure 与 clojure 1.2 master 分支一起使用吗?

python - Django 迁移 ProgrammingError : syntax error at or near ""

emacs - 如何加载 ansi-term/multi-term 的别名和环境变量?

emacs - Emacs是否具有单词和行补全功能(例如Vim的插入模式补全功能)?

python - Sentinel-2数据: plotting RGB Composite Image using Python3

python - 使用 csv 文件,查找温度平均值

python - 如何使用 __enter__/__exit__ 方法对类进行单元测试?

javascript - 事件/异步语言列表