Issue
is there a way to setup a virtual environment in Julia using an environment file? (for instance like href="https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually" rel="nofollow noreferrer">.yml file for creating conda venv)
Julia Version: 1.7.1
OS: Windows 10
Solution
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).
Answered By - Przemyslaw Szufel Answer Checked By - David Goodson (WPSolving Volunteer)