Skip to content

Instantly share code, notes, and snippets.

@leptoid
Forked from rasmi/setup.md
Created May 23, 2020 13:29
Show Gist options
  • Save leptoid/4fae1ad253d3b7c7e9d564763516f54f to your computer and use it in GitHub Desktop.
Save leptoid/4fae1ad253d3b7c7e9d564763516f54f to your computer and use it in GitHub Desktop.
Python development environment setup on Chromebook

Python development environment setup on Chromebook

Check for updates

Do this first!

sudo apt-get update && sudo apt-get dist-upgrade

Set root password

sudo passwd root

Text Editors

Sublime

Download and install Sublime by adding its repository:

sudo apt-get install wget gnupg gnupg1 gnupg2
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee  /etc/apt/sources.list.d/sublime-text.list
sudo apt-get update
sudo apt-get install sublime-text

In your user settings (Preferences > Settings), add "dpi_scale": 2 so that the text is reasonably sized on a HiDPI screen.

VSCode

Follow the instructions here (you will need to wget the linked .deb file first).

See here for instructions on how to edit the DPI settings.

Other

Optionally, install nano:

sudo apt-get install nano

Python

python2, python3, pip, virtualenv

sudo apt-get install build-essential libssl-dev libffi-dev
sudo apt-get install python python-dev python-pip
sudo apt-get install python3 python3-dev python3-pip

Add the following lines to your ~/.profile to add ~/.local/bin/ to your PATH:

# Add local bin to PATH
export PATH="$PATH:$HOME/.local/bin"

Then run source ~/.profile to load these environment variables into the current shell.

virtualenv

pip install --user virtualenv

pipenv

Optionally, install pipenv. This might briefly break the system pip -- if it does, run the second command to fix it. Alternatively, consider using poetry instead.

pip install --user pipenv
# Only run the next command if pip is broken after installing pipenv
# (see here: https://github.com/pypa/pip/issues/5599#issuecomment-414157896 )
# python -m pip uninstall pip

Create virtualenvs

Create two virtualenvs, one for python2 and one for python3:

mkdir -p ~/Projects/virtualenvs
cd ~/Projects/virtualenvs
virtualenv -p python3 pythonenv
virtualenv -p python2 python2env

Add the following lines to your ~/.profile to prevent installation of packages outside of a virtualenv. You can use the gpip alias to circumvent this.

export PIP_REQUIRE_VIRTUALENV=true
gpip() {
    PIP_REQUIRE_VIRTUALENV="" pip "$@"
}

Add the following lines to your ~/.profile to easily activate your virtualenvs with aliases.

alias pythonenv="source ~/Projects/virtualenvs/pythonenv/bin/activate"
alias python2env="source ~/Projects/virtualenvs/python2env/bin/activate"

Then run source ~/.profile.

Install pydata libraries

pythonenv
pip install numpy pandas ipython jupyter
jupyter notebook .

This will open a new tab at http://penguin.linux.test:8888/tree?token=... which will not work. Change penguin.linux.test to localhost to fix this.

gcloud

Install and set up the Google Cloud SDK:

export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install google-cloud-sdk

Optionally, install extra packages:

sudo apt-get install google-cloud-sdk-app-engine-python

Set up account credentials and other defaults:

gcloud init

SSH key setup

Generate a new ssh key:

ssh-keygen -t rsa -b 4096 -C "email@example.com"

If you set a passphrase on your ssh key, install keychain to manage it:

sudo apt-get install keychain

Add the following lines to your ~/.profile to only ask for your ssh key passphrase upon startup.

# Add ssh key to keychain
eval $(keychain -q --eval id_rsa)

Then run source ~/.profile.

Github

Optionally, add the SSH key to your GitHub account and test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment