PATH 和 exec-path 已设置,但 emacs 找不到可执行文件 [英] PATH and exec-path set, but emacs does not find executable
问题描述
我的 .emacs 包含
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 是 latex/pdflatex/.. 所在的位置./opt/local/bin/是可以找到 gs 的地方.
/usr/texbin is where latex/pdflatex/.. are located. /opt/local/bin/ is where gs can be found.
然而,当我运行 preview-at-point 时,显然需要 Latex 和 gs,我得到
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
这意味着可以找到乳胶,但不能找到 gs.
which means that latex could be found all right, but not gs.
我不确定是否需要设置 exec-path,也许 PATH 就足够了,但我已将其设置为调试措施.
I am not sure whether setting exec-path is necessary, perhaps PATH is enough, but I've set it as a debugging measure.
为什么 emacs 找不到 gs,即使它所在的目录在 PATH 和 exec-path 中?
Why can emacs not find gs even though the directory it's in is in both PATH and exec-path?
推荐答案
如果您在 Emacs 中设置 $PATH
,您很可能在 OS X 上.GUI 应用程序不是通过您的shell,所以他们看到不同的环境变量.
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.
这是我用来确保 Emacs 中的 $PATH
与我在启动终端时看到的相同的技巧(但请参阅下面的更新"):
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 "[
]*$" "" (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 文件中调用.我把那个代码on github,顺便说一句.
Then simply call the set-exec-path-from-shell-PATH
function, perhaps from your Emacs init file. I keep that code on github, BTW.
更新:此代码现已改进并发布为名为 的 elisp 库exec-path-from-shell;MELPA 中提供了可安装的软件包.
Update: this code has now been improved and published as an elisp library called exec-path-from-shell; installable packages are available in MELPA.
这篇关于PATH 和 exec-path 已设置,但 emacs 找不到可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!