Cheatsheets

Setup

For setting things up in a new computer or on a fresh os installation.

IDE

Visual Studio Code or Codium

My current IDE.

TODO: Add more on your setup.

Jupyter lab

jupyterlab_shortcuts: Jupyter lab shortcuts are described here and there markdown file was downloaded from here.

Managing kernels
  • Installing new kernels (ensure the environment is active before running this)

    python -m ipykernel install --user --name kernel_name --display-name "kernel_name"
  • Checking installed kernels: jupyter kernelspec list

Virtual environments

Python virtual env

Easiest. For quick virtual env tests.

python3 -m venv .
source bin/activate

Virtualfish

Note: I no longer use virtual fish. I mostly use conda these days.

Use virtualfish if you are using fish terminal.

pipx install virtualfish

Also install the following plugins if possible and refer to this page for more details on the plugins.

vf install compat_aliases projects environment

This will allow you to use the following:

  • workon <envname> = vf activate <envname>
  • deactivate = vf deactivate
  • mkvirtualenv [<options>] <envname> = vf new [<options>] <envname>
  • mktmpenv [<options>] = vf tmp [<options>]
  • rmvirtualenv = vf rm <envname>
  • lsvirtualenv = vf ls
  • cdvirtualenv = vf cd
  • cdsitepackages = vf cdpackages
  • add2virtualenv = vf addpath
  • allvirtualenv = vf all
  • setvirtualenvproject = vf connect

This works well for standard python packages with M1 support. If there are problems with the packages, try the below approach

Conda

Virtualfish works fine for most environments and use cases. However, if you need specific python version or if you need it for a particular architecture (like i386 in M1 macs), using virtual fish becomes tricker. One way is to use pyenv to maintain different python versions, and using rosetta terminal to run and install pyenv for i386, like described here. I found it a bit complicated.

I found an alternate approach here and realized conda might be better for these sort of things (instead of pyenv). I installed conda using brew and ran conda init fish to set up the env for fish environment. I created an i386 environment as described in here and it worked easily (later created a function for it too). I recommend using it.

Here is some stuff I found about conda (didn’t know too much about it till then):

Once a conda environment is created, if you want to use it with jupyter lab, just install ipykernel (and maybe ipywidgets) and link jupyter (as always).

  • conda install ipykernel ipywidgets
  • python -m ipykernel install --user --name env_name --display-name "env_name"
Things to avoid
  • DO NOT update from miniforge 4 to 22. It will break openssl. I had to reinstall it after messing it up. Luckily it was easy.
Tricks and tips
  • If you initialize fish shell, it will add a line into your fish config. That makes the terminal slow as it activates conda everytime. Instead, you can create an alias and activate it when you want.
  • I created a fish function to combine init and activating an environment.
About conda and mini-forge

Differences between conda and mini-forge