Skip to content

Instantly share code, notes, and snippets.

@slyphon
Created June 22, 2019 18:16
Show Gist options
  • Save slyphon/a7115dfd9b5a3b509d580e2a6f0d2084 to your computer and use it in GitHub Desktop.
Save slyphon/a7115dfd9b5a3b509d580e2a6f0d2084 to your computer and use it in GitHub Desktop.
a non-authoritative short guide on how i do python dev.

Install pyenv, virtualenv, and the pyenv-virtualenv plugin

I have the following in my shell to load up pyenv if i want it, this is optional and you can just always load it up if you follow the standard installation instructions:

s-pyenv() {
  [[ -n "${PYENV_SHELL}" ]] && return 0

  unset PYENV_VERSION || true

  if [[ -d "$HOME/.pyenv" ]]; then
    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
  fi

  if which 'pyenv' &>/dev/null; then
    eval "$(pyenv init -)"

    [[ -n "$PYENV_VIRTUALENV_INIT" ]] && return 0

    if which 'pyenv-virtualenv-init' &>/dev/null; then
      eval "$(pyenv virtualenv-init -)"
    fi
  fi
}

install a python version:

$ pyenv install --list |less
$ pyenv install 3.7.1

create a virtualenv for the python version you just installed

$ pyenv virtualenv 3.7.1 project-name

activate that environment for the current shell

$ pyenv shell project-name

now run pip to install whatever you need and it will be placed in the virtualenv for that version of python

$ pip install jupyter

to list your virtualenvs:

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