Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R renv vs Python virtual environments vs Julia environments

Are the three cited "virtualisations" solutions (renv for R, virtual environments for Python and environments for Julia) comparable, in the sense that they try to answer to the same needs (project isolation, reproducibility,...) and provide the same "solutions" or do they significantly differ in scopes and/or implementation ?

like image 411
Antonello Avatar asked Oct 18 '25 04:10

Antonello


1 Answers

I cannot answer for renv, as I have no experience with it. But I can at least talk about the difference between Python virtual environments and Julia environments.

As you surmised, Python virtual environments and Julia environments answer to the same needs: project isolation and reproducibility (and all stuff generally associated with environments). However, they answer to those needs in very different ways.

Python virtual environments are basically folders containing a full copy of the Python stack used to create them, i.e. they contain a separate python executable, the full stack associated with it, and a separate site-packages folder to contain all the Python packages installed in that environment, included a separate copy of pip and setuptools. That's how full isolation is achieved: each environment handles installation of packages fully independently. To use a virtual environment, you activate them, which consists in temporarily preprending the path to the folder containing that specific Python executable to your PATH environment variable, so that running python on the command line runs the right version. This makes Python virtual environments relatively easy to understand and use, but relatively heavyweight, since you basically have a full copy of the Python stack, including a full set of packages (with possibly lots of duplicated packages in multiple environments), for each environment you create.

Julia, on the other hand, was built with environment management built in. It's part and parcel of the language rather than an add-on as with Python. Because of that, environments are handled from within the language itself. A Julia environment, then, is just a folder with a Project.toml inside. That's all. Julia packages are installed in a location called a depot, where multiple versions of the same package can co-exist. When you add a package to a Julia environment, Julia (after dependency resolution) first checks whether the needed version of the package in question is already in the depot. If it is, it will use that version of the package. Only if the needed version of the needed package is missing will it download it. This means that a version of a package will only be installed once, and multiple environments can reuse the same package while still being isolated from each other. Activating an environment in Julia simply means making it use the Project.toml in that particular folder to decide which packages to use. This architecture makes Julia environments particularly lightweight. Also, it allows what one calls "stacked environments", where you can basically activate multiple environments, and Julia will choose which package to use by searching them all in turn (as it happens, in general when you run Julia with an environment activated, it's always stacked on the default environment, which is always activated).

I hope this helps. As you can see, Python virtual environments and Julia environments couldn't be more different from an implementation point of view.

like image 169
Tsela Avatar answered Oct 19 '25 19:10

Tsela