Embarking on the journey from Python to Rust can feel like swapping a trusty lightsaber for a new kind of blade — exciting but a bit daunting. As a data scientist deeply familiar with Python’s quirks, diving into the Rust world is a thrilling new challenge. In this article, I’ll share my experiences and insights, comparing how these two powerful languages handle a key aspect of software development — particularly focusing on (virtual) environments and dependency management.
When using Python, one of the first things you learn is to work in so called virtual environments. It is a crucial tool for managing dependencies and isolating project-specific packages such that they do not interfere with other projects or the system-wide Python installation. I wrote an article on how I manage Python a few years ago but it is still relevant (it changed a bit with micromamba and poetry, let me know if I should write an article about that).
TLDR: Just use cargo and you will be fine most of the time — Dennis
After installing Rust using rustup, my first question was: how should I create a virtual environment? To me this is a very sensible question as Rust also can use many packages (called Crates) as dependencies. The truth is that cargo solves this problem very elegantly. Below are my findings in comparing virtual environments and pip to the Rust’s cargo build system.
Disclaimer: As I navigate these Rustic landscapes, my proficiency with the language may still be a bit Rusty (pun intended). Join me in this learning adventure as we unravel the nuances of Cargo and bid farewell to the familiar embrace of virtual environments.
Virtual environments in Python are created with tools like venv, virtualenv, or conda on a per-project basis. Under the hood, these systems create a separate folder which holds the Python distribution and all its packages. Now, when we install a package with pip or conda, the package and all its dependencies are installed in this isolated folder. These virtual environment tools do…