Skip to content

Instantly share code, notes, and snippets.

@rohanishervin
Last active January 12, 2020 06:59
Show Gist options
  • Save rohanishervin/c43d4ddf9cac46fa615e0c9e9c99c6b8 to your computer and use it in GitHub Desktop.
Save rohanishervin/c43d4ddf9cac46fa615e0c9e9c99c6b8 to your computer and use it in GitHub Desktop.

Python Virtualenvs

This is the method I use to install different versions of python on different virtualenvs, which is also compatible with spacemacs autocompletion.

Installation (Arch family)

Install pyenv and pyenvvirtualenvwrapper (do not install pyenv-virtualenv)

If you already installed python-virtualenvwrapper from pacman or pip directly, remove it. These steps only work well on a fresh installation.

pacman -S pyenv
yay -S pyenv-virtualenvwrapper
pyenv virtualenvwrapper

Configuration

add following lines in to your .zshrc file,

eval "$(pyenv init -)"
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"

Don’t forget to close and reopen the shell or,

source $HOME/.zshrc

Usage

Get the available python versions you can install from pyenv,

pyenv install --list

What I usually use, (it works well with tf1.13. Checkout tested build if you need to use tf.)

pyenv install 3.7.4 

list all available python versions,

pyenv versions

switch to python version you want,

pyenv global 3.7.4
pyenv local 3.7.4

Create virtualenv (with virtualenvwrapper),

mkvirtualenv <venv-name>  

Spacemacs configuration

The following steps make the spacemacs autocompletion working,

pyenv global 3.7.4
mkvirtualenv <venv-name>
workon <venv-name>
pip install flake8 isort yapf python-language-server

Then open the spacemacs and first activate the virtualenv you want, then open the python project.

Create Ipython Kernels

Activate the virtualenv, then run:

ipython kernel install --user --name=<name-you-want>

References:

https://gist.github.com/eliangcs/43a51f5c95dd9b848ddc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment