Open XushanLu opened 3 years ago
This has nothing to do vterm. Use exec-path-from-shell
Okay, I tried using exec-path-from-shell and I don't think it works. I also tried to set 'vterm-environment' and it does not work either. Is it possible that this is caused by Mac OS security integrity protection (SIP)?
You need to specify the environment variables you want to copy
https://github.com/purcell/exec-path-from-shell/blob/master/exec-path-from-shell.el#L85
Do I just directly modify that file directly? I did so and run M-x exec-path-from-shell-initialize
and M-x exec-path-from-shell-copy-env
. Then opened a new vterm buffer and tried echo $DYLD_LIBRARY_PATH
. Nothing prints.
Now the file looks like
(defcustom exec-path-from-shell-variables
'("PATH" "MANPATH" "DYLD_LIBRARY_PATH")
"List of environment variables which are copied from the shell."
:type '(repeat (string :tag "Environment variable"))
:group 'exec-path-from-shell)
You either customize it with M-x customize-option exec-path-from-shell-variables
or set it in your init file with (setf exec-path-from-shell-variables '(...))
I used the first method to do the customization. But I do not think I am getting anything by echo $DYLD_LIBRARY_PATH
.
Did you restart emacs?
Yes. Restarted. Now the weird thing is that I cannot do the customization anymore if I customize-option
because there is now no exec-path-from-shell-variables
option anymore. But in my dotspacemacs file, there is this line
'(exec-path-from-shell-variables '("PATH" "MANPATH" "DYLD_LIBRARY_PATH"))
So, you don't think this is caused by Mac OS SIP?
I customize-option because there is now no exec-path-from-shell-variables option anymore
That usually means exec-path-from-shell
wasn't loaded when you init. This package needs to be one of the first thing that loads after emacs has started.
Okay, I now added (require 'exec-path-from-shell)
somewhere in my dotspacemacs file and it seems to be working, i.e., the package is now initialized and I am able to customize it again. Please see the following screenshot
But still nothing prints! Did I customize it correctly?
Actually, you might be right, seems rbenv and pyenv had similar issues with DYLD_LIBRARY_PATH
. Best find a way so you don't have to use it. But in any case, the title of the ticket is not correct, the shell process spawned by vterm just inherits whatever emacs is using, this is special case.
Okay, it seems that I really need to disable SIP if I want to use vterm the way I wanted.
I don't think what I said in the title was wrong. My terminal gives me the correct variable values with echo $DYLD_LIBRARY_PATH
but vterm does not. However, it is true that vterm picks up all environment variables generated by running env
in my terminal.
This was originally reported to Spacemacs, but got diverted back here.
Description
The environment variable DYLD_LIBRARY_PATH is different from what I got from using terminal. That variable is unset in vterm but properly set in terminal. This caused my compiled executables not able to find the dynamic library with the following error:
dyld: Library not loaded: @rpath/libmkl_intel_lp64.1.dylib
.The code runs perfectly fine within terminal.
Reproduction Guide
echo $DYLD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH
Observed behavior
Expected behavior
System info
Is this behavior caused by the Mac OS Security Integrity Protection? See here and here.