akermu / emacs-libvterm

Emacs libvterm integration
GNU General Public License v3.0
1.7k stars 136 forks source link

Vterm does not have the same environment variable as native terminal on Mac OS Big Sur #528

Open XushanLu opened 3 years ago

XushanLu commented 3 years ago

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

Observed behavior

Expected behavior

System info

wyuenho commented 3 years ago

This has nothing to do vterm. Use exec-path-from-shell

XushanLu commented 3 years ago

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)?

wyuenho commented 3 years ago

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

XushanLu commented 3 years ago

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.

XushanLu commented 3 years ago

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)
wyuenho commented 3 years ago

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 '(...))

XushanLu commented 3 years ago

I used the first method to do the customization. But I do not think I am getting anything by echo $DYLD_LIBRARY_PATH.

wyuenho commented 3 years ago

Did you restart emacs?

XushanLu commented 3 years ago

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?

wyuenho commented 3 years ago

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.

XushanLu commented 3 years ago

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 image

But still nothing prints! Did I customize it correctly?

wyuenho commented 3 years ago

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.

XushanLu commented 3 years ago

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.