[英]Changing python interpreter for emacs
Emacs 使用舊版本的 python(2.3) 我有默認的 python 模式,有沒有辦法告訴 emacs 使用我在主目錄中的新版本?
順便說一句,我使用的是紅帽發行版並且沒有 root 權限。
檢查您想要調整的自定義組是一個好習慣。 做就是了:
M-x customize-group RET python RET
您現在有多種選擇,其中一個應該很有趣:
Python Python Command
您可以在那里對其進行自定義並保存以供后續會話使用。
嘗試添加到您的~/.emacs
文件中:
(setq python-python-command "~/your/python/bin-dir/python")
或者
Emacs 運行的 python 命令通常是python
,因此您可以嘗試更改路徑的簡單方法:
export PATH=~/your/python/bin-dir:$PATH
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
在 Windows 10 上,我安裝了兩個版本的 Python:
C:\\ProgramData\\chocolatey\\bin
C:\\Program Files\\Python36\\
Emacs 使用的是 v3.5,但我更喜歡它使用 v3.6。 因此,我通過編輯環境變量執行以下操作來糾正此問題:
Edit the system environment variables
-> Environment Variables...
System variables
,選擇Path
variable -> Edit...
-> New
Move up
以將新文件路徑置於其他 Python 目錄之上。 在我上面的#4 & #5 的情況下,我添加了C:\\Program Files\\Python36\\
( C:\\Program Files\\Python36\\
目錄),然后將它移到C:\\ProgramData\\chocolatey\\bin
(v3.5 目錄)之上
我知道這個問題是關於全局 python 解釋器的,但是很多人可以到達這里尋找為每個項目設置一個 python 解釋器的常見問題。
假設每個項目都有一個 virtualenv,一個好的解決方案是在位於項目根目錄的.dir-local.el文件中設置 python 解釋器。
.dir-local.el 示例:
(
(python-mode . (
(python-shell-interpreter . "~/my_project/venv/bin/python")
(flycheck-checker . python-pylint)
(flycheck-python-pylint-executable . "~/myproject/venv/bin/python")
(flycheck-pylintrc . "~/my_project/.pylintrc")
)
)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.