-
-
Save gabrielloliveira/07fefba56d83f7db18988b5a6f2ccf5e 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 <henrique@bastos.net> | |
PY3=3.8.0 | |
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 .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 | |
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 jupyter38 | |
pyenv virtualenv $PY3 tools38 | |
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/jupyter38/bin/pip install --upgrade pip | |
~/.pyenv/versions/tools38/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/jupyter38/bin/pip install jupyter | |
~/.pyenv/versions/jupyter38/bin/python -m ipykernel install --user | |
~/.pyenv/versions/jupyter38/bin/pip install jupyter_nbextensions_configurator rise | |
~/.pyenv/versions/jupyter38/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/tools38/bin/pip install $PY3TOOLS | |
# Install virtualenvwrapper | |
~/.pyenv/versions/tools38/bin/pip install virtualenvwrapper | |
cat <<"EOT" >> .bash_profile | |
# Virtualenv Wrapper initialization | |
VIRTUALENVWRAPPER_PYTHON=~/.pyenv/versions/tools38/bin/python | |
source ~/.pyenv/versions/tools38/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 jupyter38 ipython27 tools38 tools27 | |
# Check everything | |
pyenv which python | grep -q "$PY3" && echo "✓ $PY3" | |
pyenv which python2 | grep -q "$PY2" && echo "✓ $PY2" | |
pyenv which jupyter | grep -q "jupyter38" && echo "✓ jupyter38" | |
pyenv which ipython | grep -q "jupyter38" && echo "✓ ipython" | |
pyenv which ipython2 | grep -q "ipython27" && echo "✓ ipython27" | |
pyenv which youtube-dl | grep -q "tools38" && echo "✓ tools38" | |
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