1

I have anaconda set up with a few different environments. When I switch environments and open vim 8.2 and type :term to launch a terminal window and type echo $PATH, $PATH does not match what is shown in a terminal outside of vim. If instead just type :!echo $PATH, it is correct

getting path from the terminal outside of vim:

(tensorflow_p36) ubuntu@ip-172-31-50-75:~$ echo $PATH
/home/ubuntu/anaconda3/envs/tensorflow_p36/bin:/home/ubuntu/anaconda3/bin:/home/ubuntu/anaconda3/condabin:/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/opt/amazon/openmpi/bin:/opt/amazon/efa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

getting path using :! echo $PATH from vim command mode (matches $PATH above):

/home/ubuntu/anaconda3/envs/tensorflow_p36/bin:/home/ubuntu/anaconda3/bin:/home/ubuntu/anaconda3/condabin:/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/opt/amazon/openmpi/bin:/opt/amazon/efa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Press ENTER or type command to continue

Opening a terminal window within vim and checking $PATH (first 11 directories are duplicates that appear later in $PATH):

(tensorflow_p36) ubuntu@ip-172-31-50-75:~$ echo $PATH                                                                                                                                          
/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/home/ubuntu/anaconda3/envs/tensorflow_p36/bin:/home/ubuntu/anaconda3/bin:/home/ubuntu/anaconda3/condabin:/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/opt/amazon/openmpi/bin:/opt/amazon/efa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Trying to understand why $PATH within a vim terminal window has additional directories prepended...

3
  • Open a normal terminal with your anaconda setup. Then just execute bash (or whatever shell you use). How does the PATH look like. – Ralf Jul 14 '20 at 22:12
  • interesting... looks the same as the last one I listed, from opening a terminal window in vim and checking PATH – froxset Jul 14 '20 at 22:22
  • There are some relatively tricky rules around what files are used to initialize bash and when. To get a taste man bash and find the section named INVOCATION. It's also possible to configure vim to do something different on top of that (e.g. with the various 'shell*' settings). I don't know much about Anaconda but that might be adding additional variables to the mix. So your question as posed has more than one possible answer. – B Layer Jul 14 '20 at 23:27
1

I don't know the "anaconda setup", but assume it is included in your shells configuration files (like .bashrc). It seems to manipulate the PATH environment variable.

When you open a terminal from within Vim a second instance of the shell is started, causing a manipulation of the PATH that was already manipulated. Hence the different value of PATH.

If this behavior is a problem, you can change your shell configuration to not repeat the anaconda stuff if it was already done.

1
  • that makes sense, thanks. I'll look in to fixing that. – froxset Jul 14 '20 at 22:56

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.