Note: Working with Python

June 9, 2023

I’m exploring the world of Machine Learning, and in that world, Python is king.

Since it had been a decade since I worked with the language, I had to set up a good development environment, starting with installing Python.

For system-wide Python, I resort to my trusty asdf version manager. It’s a great tool that allows me to install multiple versions of Python and switch between them easily.

I also want pyright and black installed with each Python installation, so I first create a file in my home directory called .default-python-packages with the following contents:


Then I run the following commands to install the plugin, install Python 3.11.4, and set it as the default:

asdf plugin add python
asdf install python 3.11.4
asdf global python 3.11.4

This manages my global Python installation, which I use for standalone scripts.

However, I need to set up a virtual environment to work on a project with dependencies. For that, I use a new tool called Rye. Rye manages everything, including the Python version – so I won’t use asdf for that.

After installing Rye, I can create a new virtual environment with the following:

rye init my-project

This will create a new directory called my-project with a rye.toml file in it. This file contains the Python version and the default packages to install. I can add more packages to it, like langchain:

cd my-project
rye add langchain

This only adds the dependency but does not install it. For that, we need to run rye sync.

That’s it! Now we have ASDF for our global Python and Rye for our projects in Python. Enjoy!

Patching Berkeley Mono with Nerd Fonts 3, 2, 1... Sleep