Skip to content

Instantly share code, notes, and snippets.

@maxbrunet
Created April 12, 2019 20:45
Show Gist options
  • Save maxbrunet/6120b14c2229c95d440f14611efa2391 to your computer and use it in GitHub Desktop.
Save maxbrunet/6120b14c2229c95d440f14611efa2391 to your computer and use it in GitHub Desktop.
Script to migrate from virtualenvwrapper to pyenv-virtualenv
#!/bin/sh
set -eu
PYTHON_EXE='python3'
VIRTUALENVWRAPPER='virtualenvwrapper.sh'
echo '>>> Sourcing virtualenvwrapper...'
. "${VIRTUALENVWRAPPER}"
echo '>>> Starting migration from virtualenvwrapper to pyenv-virtualenv...'
VIRTUALENVS=$(lsvirtualenv -b)
for venv in ${VIRTUALENVS}; do
printf '>>> Migrating %s...\n' "${venv}"
printf '>>> Creating pyenv-virtualenv for %s...\n' "${venv}"
pyenv virtualenv --python="${PYTHON_EXE}" "${venv}"
printf '>>> Reinstalling packages in new pyenv-virtualenv from %s/%s...\n' "${WORKON_HOME}" "${venv}"
"${WORKON_HOME}/${venv}/bin/pip" freeze \
| PYENV_VERSION="${venv}" pyenv exec pip install -r /dev/stdin
printf '>>> %s: Done' "${venv}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment