MacVim uses wrong Python Virtualenv

2019-07-17 06:30发布

问题:

I want to use the virtualenv's python to execute the current buffer using :!python % <Enter>. However, MacVim uses the system python instead of the virtualenv's python.

I've implemented this answer, but :!python %<Enter> still doesn't behave properly. Here's an example of what I mean -- these commands have the virtualenv activated (managed with virtualenvwrapper, it that matters)

  • In the shell: which python --> /Users/myuser/.virtualenvs/MyVirtualEnv/bin/python --> OK
  • MacVim: :python import sys; print sys.executable<Enter> --> /Users/myuser/.virtualenvs/MyVirtualEnv/bin/python --> OK
  • MacVim: :!which python<Enter> --> /usr/bin/python --> NOT OK

Since the last one is most similar to how I'm executing the buffer, could you help explain how I can achieve :!python %<Enter> in MacVim using the existing virtualenv's python?

EDIT: Also, I have this alias to use a command-line MacVim:

alias vim=/usr/local/Cellar/macvim/7.3-66/MacVim.app/Contents/MacOS/Vim

Also, this is the output of :echo $PATH<Enter> in MacVim:

  • MacVim: :echo $PATH<Center>

/Users/myuser/.virtualenvs/MyVirtualEnv/bin:/Users/myuser/.virtualenvs/MyVirtualEnv/bin:/Users/myuser/.virtualenvs/MyVirtualEnv/bin:/Users/myuser/.rbenv/shims:/Users/myuser/.rbenv/bin:/usr/local/opt/coreutils/libexec/gnubin:/Users/myuser/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/java/bin:/usr/lib64/java/jre/bin:/usr/lib64/java/bin:/usr/lib64/kde4/libexec:/opt/kde3/lib64/qt3/bin:/opt/kde3/bin:/usr/lib64/qt/bin:/usr/share/texmf/bin:.:/usr/local/Cellar/go/1.0.3/bin