【问题标题】:Emacs shell doesn't recognize python commandEmacs shell 无法识别 python 命令
【发布时间】:2021-04-27 13:59:31
【问题描述】:

我一直在尝试在 emacs 中进行一些 python 编码,但 emacs 的外壳无法编译我的代码。它一直显示此错误“python”不被识别为内部或外部命令, 可运行的程序或批处理文件。我已经将我的 Python 路径添加到系统变量中,因此它可以在命令提示符下正确运行 python,但不能在 emacs shell 中运行 这是我的 init.dl 文件

(require 'package)

;; Adds the Melpa archive to the list of available repositories
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)

;; Initializes the package infrastructure
(package-initialize)

;; If there are no archived package contents, refresh them
(when (not package-archive-contents)
  (package-refresh-contents))

;; Installs packages
;;
;; myPackages contains a list of package names
(defvar myPackages
  '(better-defaults    ;; Set up some better Emacs defaults
    elpy               ;;Emacs lisp python environment
    material-theme                  ;; Theme
    )
  )

;; Scans the list in myPackages
;; If the package listed is not already installed, install it
(mapc #'(lambda (package)
          (unless (package-installed-p package)
            (package-install package)))
      myPackages)

;; ===================================
;; Basic Customization
;; ===================================

;;(setq inhibit-startup-message t)    ;; Hide the startup message
;;(load-theme 'material t)            ;; Load material theme
(global-linum-mode t)               ;; Enable line numbers globally

;; ====================================
;; Development Setup
;; ====================================
;; Enable elpy
(elpy-enable)

【问题讨论】:

  • 在 emacs 中有多种调用 shell 的方法。你用的是哪一个?
  • 我输入 M-x shell
  • 您使用的是哪个操作系统?
  • Windows 7(32 位)

标签: python shell emacs compilation command


【解决方案1】:

这个包会帮助你:exec-path-from-shell

你可以通过 Emacs 的内置包管理器 Melpa 运行安装它

M-x package-install RET exec-path-from-shell RET

然后,将以下行放入您的 init file 并重新启动 Emacs:

(exec-path-from-shell-initialize)

【讨论】: