-
-
Save christophermoura/cb72189d043c115ecc279d510481897b to your computer and use it in GitHub Desktop.
The definitive guide to setup my Python workspace
This file contains hidden or 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 to use zsh and Python 3.9.2 | |
PY3=3.9.2 | |
PY2=2.7.16 | |
PY3TOOLS="youtube-dl s3cmd fabric pytest" | |
PY2TOOLS="rename mercurial" | |
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 .zshenv | |
cat <<EOT >> .zshenv | |
# Virtualenv-wrapper directories | |
export WORKON_HOME=$VENVS | |
export PROJECT_HOME=$PROJS | |
EOT | |
cat <<"EOT" >> .zshenv | |
# 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 | |
pyenv install $PY2 | |
# Mojave issue | |
# SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 pyenv install $PY3 | |
# SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk MACOSX_DEPLOYMENT_TARGET=10.14 pyenv install $PY2 | |
# Prepare virtual environments | |
pyenv virtualenv $PY3 jupyter39 | |
pyenv virtualenv $PY3 tools39 | |
pyenv virtualenv $PY2 ipython27 | |
pyenv virtualenv $PY2 tools27 | |
~/.pyenv/versions/$PY3/bin/pip install --upgrade pip | |
~/.pyenv/versions/$PY2/bin/pip install --upgrade pip | |
~/.pyenv/versions/jupyter39/bin/pip install --upgrade pip | |
~/.pyenv/versions/tools39/bin/pip install --upgrade pip | |
~/.pyenv/versions/ipython27/bin/pip install --upgrade pip | |
~/.pyenv/versions/tools27/bin/pip install --upgrade pip | |
# Install Jupyter | |
~/.pyenv/versions/jupyter39/bin/pip install jupyter | |
~/.pyenv/versions/jupyter39/bin/python -m ipykernel install --user | |
~/.pyenv/versions/jupyter39/bin/pip install jupyter_nbextensions_configurator rise | |
~/.pyenv/versions/jupyter39/bin/jupyter nbextensions_configurator enable --user | |
# Install Python2 kernel | |
~/.pyenv/versions/ipython27/bin/pip install ipykernel | |
~/.pyenv/versions/ipython27/bin/python -m ipykernel install --user | |
# Install Python3 Tools | |
~/.pyenv/versions/tools39/bin/pip install $PY3TOOLS | |
# Install virtualenvwrapper | |
~/.pyenv/versions/tools39/bin/pip install virtualenvwrapper | |
cat <<"EOT" >> .zshenv | |
# Virtualenv Wrapper initialization | |
VIRTUALENVWRAPPER_PYTHON=~/.pyenv/versions/tools39/bin/python | |
source ~/.pyenv/versions/tools39/bin/virtualenvwrapper.sh | |
EOT | |
# Install Python2 Tools | |
~/.pyenv/versions/tools27/bin/pip install $PY2TOOLS | |
# Protect lib dir for global interpreters | |
chmod -R -w ~/.pyenv/versions/$PY2/lib/ | |
chmod -R -w ~/.pyenv/versions/$PY3/lib/ | |
# Setup path order | |
pyenv global $PY3 $PY2 jupyter39 ipython27 tools39 tools27 | |
# Check everything | |
pyenv which python | grep -q "$PY3" && echo "✓ $PY3" | |
pyenv which python2 | grep -q "$PY2" && echo "✓ $PY2" | |
pyenv which jupyter | grep -q "jupyter39" && echo "✓ jupyter39" | |
pyenv which ipython | grep -q "jupyter39" && echo "✓ ipython" | |
pyenv which ipython2 | grep -q "ipython27" && echo "✓ ipython27" | |
pyenv which youtube-dl | grep -q "tools39" && echo "✓ tools39" | |
pyenv which rename | grep -q "tools27" && echo "✓ tools27" | |
echo "Done! Restart the terminal." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment