PATH 和 exec-path 设置,但 emacs 找不到可执行文件

发布于 2024-12-22 12:55:05 字数 751 浏览 0 评论 0原文

我的 .emacs 包含

(setenv "PATH" (concat ".:/usr/texbin:/opt/local/bin" (getenv "PATH")))
(setq exec-path (append exec-path '(".:/usr/texbin:/opt/local/bin")))

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
(require 'tex-site)
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

/usr/texbin 是 Latex/pdflatex/.. 所在的位置。 /opt/local/bin/ 是可以找到 gs 的位置。

然而,当我运行 Preview-at-point 时,它显然需要 Latex 和 gs,我得到

Preview-DviPS finished at Thu Dec 22 11:25:46
DviPS sentinel: Searching for program: No such file or directory, gs

这意味着可以找到 Latex,但不能找到 gs。

我不确定设置 exec-path 是否有必要,也许 PATH 就足够了,但我已将其设置为调试措施。

为什么 emacs 找不到 gs,即使它所在的目录同时在 PATH 和 exec-path 中?

My .emacs contains

(setenv "PATH" (concat ".:/usr/texbin:/opt/local/bin" (getenv "PATH")))
(setq exec-path (append exec-path '(".:/usr/texbin:/opt/local/bin")))

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
(require 'tex-site)
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

/usr/texbin is where latex/pdflatex/.. are located.
/opt/local/bin/ is where gs can be found.

And yet when I run preview-at-point, which apparently needs both latex and gs, I get

Preview-DviPS finished at Thu Dec 22 11:25:46
DviPS sentinel: Searching for program: No such file or directory, gs

which means that latex could be found all right, but not gs.

I am not sure whether setting exec-path is necessary, perhaps PATH is enough, but I've set it as a debugging measure.

Why can emacs not find gs even though the directory it's in is in both PATH and exec-path?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜夜流光相皎洁 2024-12-29 12:55:05

如果您在 Emacs 中设置 $PATH,那么您很可能使用的是 OS X。GUI 应用程序不是通过 shell 启动的,因此它们会看到不同的环境变量。

这是我用来确保 Emacs 内的 $PATH 与我在启动终端时看到的相同的技巧(但请参阅下面的“更新”):

(defun set-exec-path-from-shell-PATH ()
  "Set up Emacs' `exec-path' and PATH environment variable to match that used by the user's shell.

This is particularly useful under Mac OSX, where GUI apps are not started from a shell."
  (interactive)
  (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "PATH" path-from-shell)
    (setq exec-path (split-string path-from-shell path-separator))))

然后简单地调用 set-exec-path-from-shell-PATH 函数,可能是从 Emacs init 文件中调用。顺便说一句,我将该代码保存在 github 上

更新:此代码现已改进并作为名为 exec-path 的 elisp 库发布-来自外壳MELPA 中提供了可安装的软件包。

If you're setting $PATH inside your Emacs, you might well be on OS X. GUI applications are not started via your shell, so they see different environment variables.

Here's a trick which I use to ensure the $PATH inside Emacs is the same one I see if I fire up a terminal (but see "update" below):

(defun set-exec-path-from-shell-PATH ()
  "Set up Emacs' `exec-path' and PATH environment variable to match that used by the user's shell.

This is particularly useful under Mac OSX, where GUI apps are not started from a shell."
  (interactive)
  (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "PATH" path-from-shell)
    (setq exec-path (split-string path-from-shell path-separator))))

Then simply call the set-exec-path-from-shell-PATH function, perhaps from your Emacs init file. I keep that code on github, BTW.

Update: this code has now been improved and published as an elisp library called exec-path-from-shell; installable packages are available in MELPA.

深空失忆 2024-12-29 12:55:05

尝试用以下内容替换第二行:

(setq exec-path (append exec-path '("/usr/texbin" "/opt/local/bin")))

Try replacing the second line with this:

(setq exec-path (append exec-path '("/usr/texbin" "/opt/local/bin")))
相守太难 2024-12-29 12:55:05

我遇到了类似的问题,但路径正确,包括尾随“:”。结果发现内部 emacs shell 程序丢失,导致出现“正在搜索程序:没有这样的文件或目录”消息。
固定为

(setq shell-file-name "bash").

I hit a similar problem, but with a correct PATH, including trailing ´:´. It turned out the internal emacs shell program was missing, resulting in a ´Searching for program: No such file or directory´ message.
Fixed with

(setq shell-file-name "bash").
看春风乍起 2024-12-29 12:55:05

您似乎在路径字符串末尾缺少路径分隔符 :

It appears you're missing a path separator : at the end of your path string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文