You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux Mint 18.3中Emacs Python解释器未正确配置求助

Fix Emacs Using System Python Instead of Anaconda Python

Hey there, let's get this sorted out so your Emacs uses your Anaconda Python for running code with Ctrl+Enter. Here are the actionable steps you can take:

1. First, confirm your Anaconda Python path

From your terminal output, we know Anaconda's Python is active there. Run this command to get its full file path:

which python

You’ll get something like /home/your-username/anaconda3/bin/python — copy this path, you’ll need it for the next steps.

2. Configure Emacs to use Anaconda Python directly

Edit your Emacs config file (either ~/.emacs or ~/.emacs.d/init.el) and add these lines, replacing the path with the one you copied:

;; Set elpy to use Anaconda Python for RPC calls
(setq elpy-rpc-python-command "/home/your-username/anaconda3/bin/python")

;; Set python-mode's default interpreter to Anaconda Python
(setq python-shell-interpreter "/home/your-username/anaconda3/bin/python")

Save the file, then restart Emacs to apply the changes.

3. Fix Emacs not loading Anaconda's environment variables (if needed)

Sometimes Emacs starts without loading your shell’s full environment variables, so it can’t find Anaconda’s Python even if it’s in your terminal PATH. To fix this, add this function to your config file:

(defun set-exec-path-from-shell-PATH ()
  (let ((path-from-shell (replace-regexp-in-string
                          "[ \t\n]*$"
                          ""
                          (shell-command-to-string "$SHELL --login -c 'echo $PATH'"))))
    (setenv "PATH" path-from-shell)
    (setq exec-path (split-string path-from-shell path-separator))))

;; Only run this in GUI Emacs to avoid terminal Emacs conflicts
(when window-system (set-exec-path-from-shell-PATH))

This makes Emacs pull the same PATH as your login shell, so it’ll pick up Anaconda’s Python just like your terminal does.

4. Verify the fix

  • Restart Emacs, then open a Python file and run M-x elpy-config — check that the "Python interpreter" field shows your Anaconda path.
  • Alternatively, start a Python shell in Emacs with M-x run-python, then run this code:
    import sys
    print(sys.executable)
    
    If it outputs your Anaconda Python path, you’re all set! Now Ctrl+Enter should use the correct interpreter for your code.

内容的提问来源于stack exchange,提问作者user2127595

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:27:38