Last active
March 27, 2023 19:23
-
-
Save henriquebastos/0a45c39115ca5b3776a93c89dbddfacb to your computer and use it in GitHub Desktop.
The definitive guide to setup my Python workspace
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
# The definitive guide to setup my Python workspace | |
# Author: Henrique Bastos <[email protected]> | |
# Updated: 2022-07-14 for reference. | |
PY3=3.10.4 | |
PY3TOOLS="youtube-dl s3cmd fabric pytest poetry requests" | |
VENVS=~/.ve | |
PROJS=~/workspace | |
# Install dependencies | |
brew install openssl readline zlib | |
# Install Pyenv | |
brew install pyenv | |
brew install pyenv-virtualenv | |
# All my virtualenvs are here... | |
mkdir -p $VENVS | |
# All my projects are here... | |
mkdir -p $PROJS | |
# Setup .bash_profile | |
cat <<EOT >> .bash_profile | |
# Virtualenv-wrapper directories | |
export WORKON_HOME=$VENVS | |
export PROJECT_HOME=$PROJS | |
EOT | |
cat <<"EOT" >> .bash_profile | |
# Pyenv initialization | |
eval "$(pyenv init -)" | |
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi | |
EOT | |
# Initialize pyenv | |
eval "$(pyenv init -)" | |
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi | |
# Install Python versions | |
pyenv install $PY3 | |
# Prepare virtual environments | |
pyenv virtualenv $PY3 jupyter | |
pyenv virtualenv $PY3 tools | |
~/.pyenv/versions/$PY3/bin/pip install --upgrade pip | |
~/.pyenv/versions/jupyter/bin/pip install --upgrade pip | |
~/.pyenv/versions/tools/bin/pip install --upgrade pip | |
# Install Jupyter | |
~/.pyenv/versions/jupyter/bin/pip install jupyter | |
~/.pyenv/versions/jupyter/bin/python -m ipykernel install --user | |
~/.pyenv/versions/jupyter/bin/pip install jupyter_nbextensions_configurator rise | |
~/.pyenv/versions/jupyter/bin/jupyter nbextensions_configurator enable --user | |
# Install Python3 Tools | |
~/.pyenv/versions/tools/bin/pip install $PY3TOOLS | |
# Install virtualenvwrapper | |
~/.pyenv/versions/tools/bin/pip install virtualenvwrapper | |
cat <<"EOT" >> .bash_profile | |
# Virtualenv Wrapper initialization | |
VIRTUALENVWRAPPER_PYTHON=~/.pyenv/versions/${PY3}/bin/python | |
source ~/.pyenv/versions/tools/bin/virtualenvwrapper.sh | |
EOT | |
# Protect lib dir for global interpreters | |
chmod -R -w ~/.pyenv/versions/$PY3/lib/ | |
# Setup path order | |
pyenv global $PY3 jupyter tools | |
# Check everything | |
pyenv which python | grep -q "$PY3" && echo "✓ $PY3" | |
pyenv which jupyter | grep -q "jupyter" && echo "✓ jupyter" | |
pyenv which ipython | grep -q "jupyter" && echo "✓ ipython" | |
pyenv which youtube-dl | grep -q "tools" && echo "✓ tools38" | |
echo "Done! Restart the terminal." |
Author
henriquebastos
commented
Dec 19, 2019
Ubuntu version:
https://github.com/stroparo/dotfiles/blob/master/recipes/pyenv.sh
Updates both ~/.bashrc and ~/.zshrc in idempotent way (running a second time will not duplicate configuration lines).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment