PATH and exec-path, but emacs does not find the executable

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 tt) (load "preview-latex.el" nil tt) 

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

And yet, when I start the preview at a point that apparently needs 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 can be found correctly, but not gs.

I'm not sure if the exec-path configuration is needed, maybe PATH is enough, but I set it as a debugging measure.

Why can't emacs find gs even if the directory is in the PATH and exec paths?

+29
emacs dot-emacs
Dec 22 '11 at 16:35
source share
4 answers

If you install $PATH inside your Emacs, you may well be in OS X. GUI applications do not run through your shell, so they see different environment variables.

Here is the trick that I use to provide $PATH inside Emacs, the same one that I see if I run the terminal ( but see the β€œ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 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 just call the set-exec-path-from-shell-PATH function, possibly from your Emacs initialization file. I save this code on github , BTW.

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

+52
Dec 22 '11 at 20:26
source share

Try replacing the second line as follows:

 (setq exec-path (append exec-path '("/usr/texbin" "/opt/local/bin"))) 
+8
Dec 22 '11 at 17:05
source share

I ran into a similar problem, but with the correct PATH, including the termination of ':'. It turned out that the internal emacs shell program is missing, which leads to a program search: there is no such file or directory. Fixed using

 (setq shell-file-name "bash"). 
+1
Mar 23 '15 at 16:00
source share

It seems you are missing the path separator : at the end of the path line.

-3
Dec 22 '11 at 16:41
source share



All Articles