Python Version and Project management

I use pyenv to manage the versions of python installed and available to my user; and then I create a virtual environment for specific use, activate it, and pip in the libraries I need. For example, I installed two specific versions of Python, then created virtual environments to enable NeoVim to use the proper Python runtime and the proper supporting libraries. 

pyenv install 2.7.11
pyenv install 3.4.4
pyenv virtualenv 2.7.15 neovim2
pyenv virtualenv 3.6.6 neovim3
pyenv activate neovim2
pip install neovim
pyenv activate neovim3
pip install neovim

Now I’m all set for NeoVim to have a runtime set to managed Python runtime for versions 2 and 3 with the neovim package installed for each. When I use the simple verison, I do not have the weight of the neovim package. Not much to worry about in this case, but when working on larger projects this isolation can be a lifesaver. By running pyenv versions you can see what’s installed and what is active.

pyenv versions
  system
  2.7.15
  2.7.15/envs/neovim2
  3.6.5
  3.6.5/envs/neovim3
* 3.6.6 (set by PYENV_VERSION environment variable)
  3.7.0
  anaconda3-5.1.0
  miniconda3-4.3.30
  neovim2
  neovim3

Let’s dial in a little bit: the pyenv package actually downloads and installs in PYENV_ROOT the executables and then allows you to switch between them for a project and for the global version of python as well.

On the other hand, the pyenv-virtualenv package is used to manage a virtual environment with its own modules isolated from other environments while inheriting the Python runtime from it’s base.

When you have pyenv-virtualenv installed you can create a symlink driven virtualenv of a pyenv installed version of python that allows you to pip install modules to just that particular virtualenv of python without changing the base version installation.

If you want to use flake with when editing your Python code in NeoVim, you run these commands:

pip install flake8
ln -s `pyenv which flake8` ~/bin/flake8

This allows flake8 to be available to linter plugins for NeoVim.

Leave a Comment