In Emacs 25 GUI, 1. Shell process loads environment variables, 2. Python process, started by run-python, doesn't load environment variables.

Run Emacs terminal mode in iTem2: Both shell and python process load environment variables.


Under OSX, Emacs itself wont, by default, load the same environment as your user unless you either:

  1. Start emacs from the shell (in terminal or gui mode)
  2. Use the exec-path-from-shell package, here
  3. Manually assemble Emacs' path from your users' PATH in your init.el (not recommended)

If all you're interested in, are the PATH and MANPATH variables, one way to get good values for those, are with this code (snipped from my emacs init file):

(let ((path-helper
   (lambda (p pd)
       (mapc (lambda (filename)
           (insert-file-contents filename)
           (goto-char (point-max))
           (unless (bolp) (insert "\n")))
         (cons p (directory-files pd t "[^.]")))
       (let (res)
     (goto-char (point-min))
     (while (< (point) (point-max))
       (setq res (cons (buffer-substring
                (point) (progn (end-of-line) (point)))
       (forward-char 1))
     (nreverse res))))))
  (setq exec-path (funcall path-helper "/etc/paths" "/etc/paths.d"))
  (setenv "PATH" (mapconcat #'identity exec-path ":"))
  (setenv "MANPATH"
      (mapconcat #'identity
         (funcall path-helper "/etc/manpaths" "/etc/manpaths.d")

But then, of course, you need to maintain the files /etc/paths, /etc/paths.d/*, /etc/manpaths, and /etc/manpaths.d/*. In any case, in the default setup, your login shell on OS X uses those files to set these variables, with the help of the path_helper utility, so this should be no great burden.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.