After my env is activated, I start vim. In the bottom of the screen I see something like this: "[Pymode] Activate virtualenv: /home/../envs/test_env" When I'm trying to run my script, vim use system base python, but not from my env. I have in my settings "let g:pymode_virtualenv = 1" What is the problem?
-
Python-mode uses the Python interpreter Vim is linked against, not your system python. Of course, this is relevant only if the two are different. – lcd047 Apr 22 '15 at 17:12
-
how did you try to run your script? if you do `:!python your_script.py` then it's your problem. – Jason Hu Aug 22 '15 at 19:11
1 Answers
Ok this is far from optimal but here it goes:
When it comes to efficiently switching between python2 and python3 venvs the main problem seems to be the fact that (I am quoting from this reply)
you need to have MacVim compiled against the Python you are using for the virtualenv
Of course it does not seem to be a mac-only issue; vim cannot support both python2 and python3 (e.g. here).
So a proposed workaround (which for the moment seems to be ok for me) is:
a. completely uninstall any existing vim installations to set the environment from scratch
b. set up a vim installation with python3 support as indicated here
c. sudo apt-get install vim-gnome (installs a python2 compliant vim)
d. set up your ~/.vimrc and the plugins in ~/.vim folder as indicated in this nice youtube tutorial
e. (I assume this should not be needed but for some reason - perhaps my fault - given that python-mode plugin is supposed to come with virtualenv support): install virtualenv plugin for vim from here. (it is then when I got access to commands such as :VirtualEnvList
, :VirtualEnvActivate
etc)
f. create 2 aliases in your .bashrc for the two vim installations of step b and c.
-> alias vim3="/opt/vim74/bin/vim"
(this came from step b)
-> alias vim2="/usr/bin/vim"
(this came from step c)
g. add the following line to your .vimrc:
let g:virtualenv_directory = "~/path/to/my/venvs"
h. switch to your venv dir, activate it and start the appropriate vim2/3. now presumably you will be able to use venvs through the appropriate commands e.g. :VirtualEnvList
etc...
hope that helps and also hope someone comes up with s.th more efficient...