23 votes
Accepted

Using conda environments in emacs

I'd suggest using pyvenv library, it provides a neat interface to selecting a virtual env among several alternatives updating interpreter and library paths. You will need to alter WORKON_HOME variable ...
user avatar
  • 524
9 votes
Accepted

Why does emacs (getenv "TERM") return incorrect data?

Quoting startup.el: ;; Subprocesses of Emacs do not have direct access to the terminal, so ;; unless told otherwise they should only assume a dumb terminal. ;; We are careful to do it late (after ...
user avatar
  • 43.9k
8 votes

How do I make tramp+eshell use my environment customized in the remote ~/.bash_profile

This question has been already answered by rekado (thanks!) (as a reply to another more general question about eshell): You can configure TRAMP to respect the PATH variable on the remote machine (...
user avatar
8 votes
Accepted

How to get the PATH from the SHELL

No, you don’t want to use -i because you’re not launching an interactive shell. That is, this shell will not be connected to a terminal that the user can type in. It is instead going to be connected ...
user avatar
  • 12.2k
7 votes
Accepted

How can I get buffer-local environment variables via .dir-locals?

Both the buffer-local and the global variable are initially pointing to the same cons cell / list. If setenv pushes a new value to the front of the list, that would only be reflected in the local ...
user avatar
  • 43.9k
6 votes

Using conda environments in emacs

I have recently incorporated Anaconda into my python development and was having similar problems setting up Emacs + flycheck + linters. This answer got me up and running, but I've modified it, since ...
user avatar
6 votes

How to make shell-command run using shell profile and current directory hooks (ex. direnv)

Running eval "$(direnv hook $0)" defines a function that hooks into $PROMPT_COMMAND, which is never called when bash is run as bash -ic because there is no prompt. You can change the line: eval "$(...
user avatar
6 votes

How to make shell-command run using shell profile and current directory hooks (ex. direnv)

This doesn't seem to be a problem with Emacs but with bash. shell-command just executes call-process on the shell and passes arguments. I tried this on a regular shell: bash -ic "cd ~/code/foo &...
user avatar
  • 5,216
6 votes
Accepted

Reload environment variables

As a workaround, the following can be used (Linux, Bash): First run printenv -0 > env.txt from the Bash terminal window, Then from within Emacs, run (defun my-update-env () (interactive) (let ...
user avatar
6 votes
Accepted

How can I get some environment variables into init.el to construct file paths?

(substitute-in-file-name "~/.emacs.d/${USER}_${HOST}_custom.el") Should give you what you want. substitute-in-file-name is a built-in function in C source code. (substitute-in-file-name FILENAME)...
user avatar
  • 10.9k
6 votes

How to check whether ImageMagick is setup correctly on macOS?

According to the doc https://www.gnu.org/software/emacs/manual/html_node/elisp/ImageMagick-Images.html you can check for imagemagick support with (image-type-available-p 'imagemagick) you could use ...
user avatar
  • 760
5 votes

What kind of environment variables does Emacs expect to find in .profile, .bash_profile etc?

By default, Emacs does not look at your shell config files. The behaviour you are seeing is on account of a third-party elisp package named exec-path-from-shell which you have installed. Maybe ...
user avatar
  • 43.9k
5 votes
Accepted

What kind of environment variables does Emacs expect to find in .profile, .bash_profile etc?

This is a feature of the emacs package exec-path-from-shell, https://github.com/purcell/exec-path-from-shell. The message is trying to do you a favour in warning about PATH variable definitions in ...
user avatar
  • 2,813
5 votes
Accepted

How to make shell-command run using shell profile and current directory hooks (ex. direnv)

Thanks to Rekado and Erik for pointing out how the direnv hook works by using $PROMPT_COMMAND. Since shell-command doesn't use a prompt, this wasn't getting executed. While Erik's answer works in my ...
user avatar
  • 1,354
5 votes

How to make terminal/shell spawned inside Emacs running on a Mac inherit the environment variables of the native terminal?

Like Mark said, Terminal and iTerm 2 invoke shells as login shells by default, so that Bash reads ~/.bash_profile but not ~/.bashrc, but M-x shell and M-x term invoke shells as non-login shells, so ...
user avatar
  • 241
5 votes

How to make terminal/shell spawned inside Emacs running on a Mac inherit the environment variables of the native terminal?

I recently started using emacs outside of the terminal which was causing me some PATH issues. I had tried setting it by adding (getenv "PATH") to my exec-path, among other things that ultimately never ...
user avatar
  • 209
5 votes
Accepted

Set environment variables for spawned subprocesses

setenv-internal and setenv change the list stored in process-environment (as local or special variable) by side-effects. It does not help if you assign the list (pointer) to a local variable process-...
user avatar
  • 30.5k
4 votes

How to make terminal/shell spawned inside Emacs running on a Mac inherit the environment variables of the native terminal?

Given the actual title here "How to make terminal/shell spawned inside Emacs running on a Mac inherit the environment variables of the native terminal?" you can't as Emacs will not have the Terminal....
user avatar
  • 311
4 votes
Accepted

How to determine the initial current directory when emacs is run from command line?

AFAICT, Emacs does not save this info in a standard place. Håkon's solution might work for you, but that completely depends on the program that launches Emacs: some will put the directory in $PWD, ...
user avatar
  • 25.4k
4 votes

Package `exec-path-from-shell` isn't setting PATH variables from `.zshenv` on MacOS

You should remove :defer f, because you don't want exec-path-from-shell to be defer loaded and you are going to use function from it when Emacs starts. Try something like the following (use-package ...
user avatar
  • 13.7k
4 votes
Accepted

Interpolate environment variables in string

I think you're looking for the function substitute-env-vars: substitute-env-vars is a compiled Lisp function in ‘env.el’. (substitute-env-vars STRING &optional WHEN-UNDEFINED) Substitute ...
user avatar
  • 11.4k
4 votes
Accepted

emacs daemon and ssh agent forwarding

Both return the same value when getenv is called on SSH_AUTH_SOCK from within an emacs client. That looks unlikely. One would return ~/.ssh/ssh_auth_sock and the other would return /path/to/HOME/....
user avatar
  • 43.9k
3 votes

How can I get some environment variables into init.el to construct file paths?

Try this: (setq custom-file (format "~/.emacs.d/%s_%s_custom.el" user-login-name (getenv "HOST"))) (when (file-exists-p custom-file) (load custom-file))
user avatar
  • 1,490
3 votes

UnicodeEncodeError in inferior python under windows

The solution is to just set the same environment variable to the same value as in your question. How that is done I was reminded of by an answer to a previous, similar question – which I asked myself, ...
user avatar
  • 290
3 votes
Accepted

How can I use 'emacsclient' as $PAGER in eshell with pipe? or any better PAGER which works well with eshell?

One option would be to disable the PAGER entirely: (setenv "PAGER" "") This dumps all output directly to the eshell buffer, so you can use normal Emacs navigation commands to navigate the output. ...
user avatar
  • 2,615
3 votes

Reload environment variables

I used to use this: function export-emacs { if [ "$(emacsclient -e t)" != 't' ]; then return 1 fi for name in "${@}"; do value=$(eval echo \"\$${name}\") ...
user avatar
3 votes

How to make shell-command run using shell profile and current directory hooks (ex. direnv)

nowadays you would likely want to use https://github.com/wbolster/emacs-direnv it works similar to the hook that direnv installs in your shell. the emacs environment is updated on request (or ...
user avatar
3 votes

How do I use a remote virtual environment with emacs?

No, You can't use a remote virtual environment with emacs with elpy as of now. Here is jorgenschaefer the author of elpy) comments on this I'm afraid that won't work. Tramp does a lot of magic with ...
user avatar
3 votes
Accepted

Run an external program with customized environment/options in current buffer

See C-hv process-environment List of overridden environment variables for subprocesses to inherit. Each element should be a string of the form ENVVARNAME=VALUE. Entries in this list take ...
user avatar
  • 43.9k

Only top scored, non community-wiki answers of a minimum length are eligible