Last active
March 28, 2020 13:11
-
-
Save nkpro2000sr/53049a2372a6e2ba2cc779b98b33c975 to your computer and use it in GitHub Desktop.
to setup pyenv and pyenv-virtualenv in linux. pyenv lets you easily switch between multiple versions of Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pyenv | |
git clone https://github.com/pyenv/pyenv.git ~/.pyenv | |
# pyenv-virtualenv | |
git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv | |
# pyenv-pip-migrate | |
git clone git://github.com/pyenv/pyenv-pip-migrate.git ~/.pyenv/plugins/pyenv-pip-migrate | |
# pyenv-update | |
git clone https://github.com/pyenv/pyenv-update.git ~/.pyenv/plugins/pyenv-update | |
# adding pyenv to environment | |
echo '#pyenv{' >> ~/.bashrc | |
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc | |
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc | |
echo 'if command -v pyenv 1>/dev/null 2>&1' >> ~/.bashrc | |
echo 'then' >> ~/.bashrc | |
echo ' eval "$(pyenv init -)"' >> ~/.bashrc | |
echo ' eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc | |
echo 'fi' >> ~/.bashrc | |
# aliases | |
echo 'alias py="pyenv "' >> ~/.bashrc | |
echo 'alias pyv="pyenv virtualenv "' >> ~/.bashrc | |
sed -ri "s/_pyenv pyenv/_pyenv pyenv py/g" ~/.pyenv/completions/pyenv.bash | |
# to uninstall pyenv | |
echo 'py-uninstall () {' >> ~/.bashrc | |
echo ' if [ `expr length "$(grep -En "^#pyenv{$|^#pyenv}$" ~/.bashrc | cut -d: -f1)"` != 0 ]' >> ~/.bashrc | |
echo ' then' >> ~/.bashrc | |
echo ' sed -i $(echo $(grep -En "^#pyenv{$|^#pyenv}$" ~/.bashrc | cut -d: -f1) | sed -r "s/ /,/g")d ~/.bashrc;' >> ~/.bashrc | |
echo ' rm -rf ~/.pyenv;' >> ~/.bashrc | |
echo ' echo "if you still getting py, manually restart shell by \`exec \$SHELL\` command"' >> ~/.bashrc | |
echo ' exec $SHELL' >> ~/.bashrc | |
echo ' fi' >> ~/.bashrc | |
echo '}' >> ~/.bashrc | |
echo '#pyenv}' >> ~/.bashrc | |
# HELP | |
echo "\`py install Version\` to install specific version of python" | |
echo "\`pyv Version VenvName\` to create virtualenv" | |
echo "\`py uninstall Version(or)VenvName\` to uninstall python version or virtualenv" | |
echo "\`py shell Version\` to change default \`python\` in current shell" | |
echo "\`py global Version\` to change default \`python\`" | |
echo "\`py local VenvName\` to change default \`python\` in \$PWD" | |
echo "\`py versions\` to get all installed versions of python and virtualenvs" | |
echo "\`py install -l\` to get all installable versions of python" | |
echo "\`py-uninstall\` to uninstall pyenv package" | |
# restating shell | |
echo "if you not getting py, manually restart shell by \`exec \$SHELL\` command" | |
exec $SHELL |
Explaining above code 😃
bit.ly/setup-pyenv is like
$ curl bit.ly/setup-pyenv
<html>
<head><title>Bitly</title></head>
<body><a href="https://gist.githubusercontent.com/nkpro2000sr/53049a2372a6e2ba2cc779b98b33c975/raw/pyenv_setup.sh">moved here</a></body>
so we have to redirect to gist link. for that curl -L bit.ly/setup-pyenv
then finally execute shell_script using sh, by piping code to sh by curl -L bit.ly/setup-pyenv | sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
memorable way to setup pyenv easily
curl -L bit.ly/setup-pyenv | sh