Skip to content

Instantly share code, notes, and snippets.

@rasmi
Last active November 1, 2023 15:46
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save rasmi/f62799958c0fca26a6f0182100f4468c to your computer and use it in GitHub Desktop.
Save rasmi/f62799958c0fca26a6f0182100f4468c 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.

@mishmam
Copy link

mishmam commented Dec 15, 2019

Thank you for putting this together. This was very helpful.

@OvidijusUlis
Copy link

I really appreciate you putting this together. As a beginner at using Linux, it's a bit hard to understand some parts. Like this part "Then run source ~/.profile.".

@rasmi
Copy link
Author

rasmi commented Jan 28, 2020

Thanks for the feedback, @OvidijusUlis. I updated the first time the command is called to clarify what it does!

@btsands
Copy link

btsands commented Feb 28, 2020

I'm curious why you're installing virtualenv (unless you're only talking about Python2). It's already included in Python3. You could just run python3 -m venv venv then $ source ./venv/bin/activate

@rasmi
Copy link
Author

rasmi commented Feb 28, 2020

Hey @btsands, good point! There is no need for it if venv meets your needs. This guide was written in 2018 when having a stack compatible with both Python 2 and 3 was important. It may also be worth switching Pipenv for Poetry.

@btsands
Copy link

btsands commented Feb 28, 2020

Aaah...makes sense; I thought this was more recent (came here from an article on setting up a Chromebook with Python 3.7). Also thanks for the tip on Poetry; will have to check that out!

@ToraMakun
Copy link

Thanks, still relevant to this day. Even though a small update would be welcome especially on the virtual environment part.

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