Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to create new virtual environment in Julia using environment file (like .yml)?

is there a way to setup a virtual environment in Julia using an environment file? (for instance like .yml file for creating conda venv)

Julia Version: 1.7.1
OS: Windows 10

like image 285
Shayan Avatar asked Dec 05 '25 06:12

Shayan


2 Answers

In Julia virtual environment is defined via Project.toml file (that keeps package names and their acceptable versions) and Manifest.toml (that keeps the exact dependence tree and package versions generated along requirements defined in Project.toml).

Here is a sample Julia session:

julia> using Pkg

julia> pkg"generate MyProject"
 Generating  project MyProject:
    MyProject/Project.toml
    MyProject/src/MyProject.jl

julia> cd("MyProject")

julia> pkg"activate ."
 Activating environment at `/home/ubuntu/MyProject/Project.toml`

Finally, note that you can manipulate the Project.toml by eg. adding a package like this (this assumes the environment is active):

pkg"add DataFrames"

Sometimes you want to provide package version information to your Project.toml, for an example you could add at the end of the file:

[compat]
DataFrames = "1.3.0" 

After adding the first dependency the Mainifest.toml file has been generated. Copying this file together with Project.toml across machines allows you to duplicate the environment. In order to have all packages installed on a new machine you will need to run:

pkg"activate ."
pkg"instatiate"

pkg"instatiate" can also be used to generate Mainfest.toml when only the Project.toml is present.

The nice thing is that Julia can store many package versions simultaneously and the virtual environments only links to the central package repository (contrary to Python that copies several GBs of data each time).

like image 187
Przemyslaw Szufel Avatar answered Dec 07 '25 16:12

Przemyslaw Szufel


pkg provides this with project.toml files.

like image 45
Oscar Smith Avatar answered Dec 07 '25 16:12

Oscar Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!