Julia is not in my wheelhouse yet, but I have been handed a Julia project to run the code within.
This consists of a directory containing a main.jl
, a Project.toml
and a Manifest.toml
.
I've read up a little on what the TOML files are for; to summarise my current understanding, they form a project or environment (not sure which, or what the real difference is).
I have installed Julia v1.3.1 at the command line by downloading the tar, decompressing and placing in my path. Typing julia
at the command line opens the Julia CLI REPL as expected.
I have tried to run the code by using julia main.jl
, this results in complaints about the required packages not being present, e.g.:
julia main.jl
ERROR: LoadError: ArgumentError: Package JSON not found in current path:
- Run `import Pkg; Pkg.add("JSON")` to install the JSON package.
Stacktrace:
[1] require(::Module, ::Symbol) at ./loading.jl:887
[2] include at ./boot.jl:328 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1105
[4] include(::Module, ::String) at ./Base.jl:31
[5] exec_options(::Base.JLOptions) at ./client.jl:287
[6] _start() at ./client.jl:460
in expression starting at /home/<user>/myproject/main.jl:3
I can follow the instructions here and load the required packages, but surely I shouldn't do this manually for every package?
As every package required is listed in the Project.toml
I guess there should be some way to tell Julia to make sure the packages in the project are made available (I'm thinking something along the lines of Python's requirements file).
I have tried julia --project=main.jl
, but this just results in the REPL loading again with nothing happening (not sure if any project or environment is loaded or not).
How can I tell Julia to run the script in this project while taking note of the requirements and other information in the TOML files?
Update:
Have figured out to enter ]
at the REPL to enter the pkg
package manager. Then I can:
(v1.3) pkg> activate .
Activating environment at `~/myproject/Project.toml`
(myproject) pkg> instantiate
(myproject) pkg>
Then leave the manager by pressing backspace. Still not sure how to "run" everything though.
You can run a Julia file (via Ctrl+F5, which will run whatever Julia file you have open and active), execute Julia commands via the REPL, or even execute a specific block of code from a file you have open.
Activating a Project Environment when starting Julia I usually start my workflow from the Bash terminal. I go to the project directory and start Julia with julia --project=. to activate the project environment as specified in the files Project. toml and Manifest. toml in the project directory.
Julia project. The Julia Project as a whole is about bringing usable, scalable technical computing to a greater audience: allowing scientists and researchers to use computation more rapidly and effectively; letting businesses do harder and more interesting analyses more easily and cheaply.
You’re very close to the solution! If the files are all in a directory dir
then the command would be
julia --project=dir main.jl
You could also start an interactive session in that environment and then run the code in the file via
julia --project=dir
julia> include(“main.jl”)
Edit: If the directory is the current working directory, then you can just use --project=.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With