Đây là những gì tôi sử dụng (xin lỗi phần đánh dấu là không hợp lệ).
" Function to activate a virtualenv in the embedded interpreter for
" omnicomplete and other things like that.
function LoadVirtualEnv(path)
let activate_this = a:path . '/bin/activate_this.py'
if getftype(a:path) == "dir" && filereadable(activate_this)
python << EOF
import vim
activate_this = vim.eval('l:activate_this')
execfile(activate_this, dict(__file__=activate_this))
EOF
endif
endfunction
" Load up a 'stable' virtualenv if one exists in ~/.virtualenv
let defaultvirtualenv = $HOME . "/.virtualenvs/stable"
" Only attempt to load this virtualenv if the defaultvirtualenv
" actually exists, and we aren't running with a virtualenv active.
if has("python")
if empty($VIRTUAL_ENV) && getftype(defaultvirtualenv) == "dir"
call LoadVirtualEnv(defaultvirtualenv)
endif
endif
Lưu ý rằng bạn cần phải có MacVim được biên dịch dựa vào Python bạn đang sử dụng cho virtualenv, ví dụ: nếu bạn đã tải Python 2.7 từ Python.org, bạn nên biên dịch lại MacVim bằng cách sử dụng --with-python-config-dir=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
làm đối số cho ./configure
.
Hy vọng điều đó sẽ hữu ích!
CHỈNH SỬA: Chỉ cần một lưu ý ghi nhận tác giả: Rất nhiều công việc thám tử đã được viết vào ditty nhỏ này được thực hiện bởi this blogger và anh xứng đáng nhận được một số tín dụng.
wow, tuyệt, đây là những gì Tôi đang tìm kiếm, cảm ơn rất nhiều! Tôi không biết virtualenv tạo ra điều này activate_this.py –
Hi dwf, bạn có thể xem câu hỏi của tôi ở đây để xem tại sao đầu ra của tôi là lạ? http://stackoverflow.com/questions/17288843/macvim-uses-wrong-python-virtualenv – Lionel