更改 emacs 的 python 解释器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2515754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 00:49:00  来源:igfitidea点击:

Changing python interpreter for emacs

pythonemacs

提问by sam

Emacs uses an older version of python(2.3) i have for the default python mode, is there a way for me to tell emacs to use the newer version that i have in my home directory?

Emacs 使用旧版本的 python(2.3) 我有默认的 python 模式,有没有办法告诉 emacs 使用我在主目录中的新版本?

btw I'm using a red hat distro and dont have root privileges.

顺便说一句,我使用的是红帽发行版并且没有 root 权限。

回答by radekg

It is good habit to check customize-groupof things you wanna tweak. Just do:

检查您想要调整的自定义组是一个好习惯。做就是了:

M-x customize-group RET python RET

you've got now multiple options of which one should be interesting:

您现在有多种选择,其中一个应该很有趣:

Python Python Command

You can customize it there and Save for further sessions.

您可以在那里对其进行自定义并保存以供后续会话使用。

回答by Chen Levy

Via .emacs:

通过.emacs:

Try to add to your ~/.emacsfile:

尝试添加到您的~/.emacs文件中:

(setq python-python-command "~/your/python/bin-dir/python")

or

或者

Via the shell environment:

通过shell环境:

The python command that is run by Emacs is typically python, so you can try the simple approach of changing your path:

Emacs 运行的 python 命令通常是python,因此您可以尝试更改路径的简单方法:

export PATH=~/your/python/bin-dir:$PATH

回答by jpkotta

python-python-commandis for the older "loveshack python.el". For recent versions of Emacs, which use "gallina python.el", use the variable python-shell-interpreter.

python-python-command适用于较旧的“loveshack python.el”。对于使用“gallina python.el”的最新版本的 Emacs,请使用变量python-shell-interpreter.

(setq python-shell-interpreter "/path/to/python")

https://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc2

https://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc2

回答by Ray

On Windows 10, I had two versions of Python installed:

在 Windows 10 上,我安装了两个版本的 Python:

  1. v3.5 installed under C:\ProgramData\chocolatey\bin
  2. v3.6 installed under C:\Program Files\Python36\
  1. v3.5下安装 C:\ProgramData\chocolatey\bin
  2. v3.6下安装 C:\Program Files\Python36\

Emacs was using v3.5 but I preferred for it to use v3.6. Therefore, I did the following to correct this by editing my Environment Variables:

Emacs 使用的是 v3.5,但我更喜欢它使用 v3.6。因此,我通过编辑我的环境变量做了以下工作来纠正这个问题:

  1. Start -> Type in "environment variables"
  2. Select Edit the system environment variables-> Environment Variables...
  3. Under System variables, select Pathvariable -> Edit...-> New
  4. Add the path to your desired Python directory
  5. Click Move upto place the new filepath above whatever the other Python directory.
  1. 开始 -> 输入“环境变量”
  2. 选择Edit the system environment variables->Environment Variables...
  3. 在 下System variables,选择Path变量 -> Edit...->New
  4. 将路径添加到所需的 Python 目录
  5. 单击Move up以将新文件路径置于其他 Python 目录之上。

In my case for #4 & #5 above, I added C:\Program Files\Python36\(v3.6 directory) and then moved it above C:\ProgramData\chocolatey\bin(v3.5 directory)

在我上面的#4 & #5 的情况下,我添加了 C:\Program Files\Python36\(v3.6 目录)然后将它移到上面C:\ProgramData\chocolatey\bin(v3.5 目录)