Wanting to try out some command line tools written in Python, I needed to install Python on my Ubuntu machine. Since it’s more than a decade without Python, I needed to lookup how that was done these days. This is what I ended up with:
sudo apt install python3 python3-is-python python3-pip pipx
And apparently, these days you can’t just install packages with pip unless you are in a virtual environment. So now you have pipx
, which I used to install ruff
.
pip instal ruff
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:
pyright
black
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!