Installing Julia packages using a .toml file?
Asked Answered
F

3

11

I am totally new to Julia!

I would like to install a large number of packages for a project I'm joining.

The project comes with a "Project.toml" file

It seems like there should be a nice way to install all the packages I need for the project, perhaps using the Project.toml file

However, I have not yet found any site that indicates how I might be able to do this.

Could anyone please let me know if what I am doing is possible, and if so, point me to a reference that would show how?

Foreglimpse answered 29/4, 2022 at 17:9 Comment(0)
N
14

If your Project.toml is located in a folder, like myproject/Project.toml, you can simply start Julia with julia --project=/path/to/myproject, and it will automatically detect the Project.toml file in myproject.

The first time you activate this project, in the REPL, you can switch to Pkg mode by typing ], and type the command instantiate. This will cause the package manager to download and install all of the packages listed in Project.toml and their dependencies.

Another way to switch between projects during interactive use is to run activate /path/to/myproject in Pkg-mode in the REPL.

Nf answered 29/4, 2022 at 17:41 Comment(3)
If i don't want to start Julia, just install the packages. is that possible?Surly
@Sanidhya Singh, if you don't want the interactive interface, you can run julia --project=/path/to/myproject -e 'using Pkg; Pkg.instantiate()'. It is necessary to run the julia executable one way or another, though.Nf
Thanks for the reply! I was looking for something like pip install -r requirements.txt but looks like you need to invoke Julia code directly to setup the environmentSurly
P
2

How to install julia packages from a Project.toml

First, you will have navigate to the folder containing your Project.toml.

cd ../your-folder-containing-the-project.toml-file

in your terminal:

julia --project=.

]

instantiate

or

julia --project=. -e 'using Pkg; Pkg.instantiate()

Polynuclear answered 28/11, 2022 at 21:25 Comment(0)
H
0

The other answers went already to the point, but I want to add another important aspect.

If this project comes "only" with a Project.toml file, you will be able to install "sone version" of these packages, eventualy the Project.toml may also give you a range of versions known to work with the project you have been given.

But if this project comes also with a Manifest.toml file you will be able to recreate on your pc the exact environment, will all the exact versions of all dependent packages recursivelly, of the guy that passed you the project, using the ways desctibed in detail in the other answers (e.g. ] activate [folder]; instantiate).

Hypochondriac answered 29/11, 2022 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.