Set up Julia for a novice

I’d like to write a script that installs a few packages, does using to trigger compilation, and replies yes to all questions. Is there a way to do this? What I’d like to do is something like

for pack in [FFTW, SparseSuite, PyPlot, IJulia]
using pack
replay "y" to all questions

I have no idea how to begin. Even without the reply "y" part, I’m having trouble with looping over a list of packages and doing both add (which uses a string) and using (which does not).

Why not just instantiate an environment?

1 Like

I’m still a confused. I’d like to do this in the default environment. Do I write a script to do this? I’d like the user to have to do as little as possible.

My target user will be reading instructions from a web page and not local to my workplace, so I can’t do this myself and send them a .julia tarball.

you can put the Manifest.toml and Project.toml into the default environment folder

OK. So when my customer puts the .toml files into a newly created .julia directory and starts Juila, will the packages automatically be added? Do I still have to tell them to do

using XXX
for all packages and reply “y” to any questions?

They will need to run Pkg.instantiate(). Notice that you can easily test these scenarios yourself. This gives you a pristine Julia depot unrelated to whatever you have in your .julia:

$ mkdir /tmp/testdepot
$ JULIA_DEPOT_PATH=/tmp/testdepot julia
   _       _ _(_)_     |  Documentation:
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.0 (2022-08-17)
 _/ |\__'_|_|_|\__'_|  |  Official release
|__/                   |

(@v1.8) pkg> st
  Installing known registries into `/tmp/testdepot`
Status `/tmp/testdepot/environments/v1.8/Project.toml` (empty project)

That’ll work, but it’s a bit more effort from my customers than I’d like.

There is a way to do what you asked for:

import Pkg
Pkg.activate("project_for_ctkelley_tutorial", shared=true)
for pack in [:FFTW, :SuiteSparse, :PyPlot, :IJulia]
    @eval using $pack

I took the liberty of adding Pkg.activate("project_for_ctkelley_tutorial", shared=true) so that your users won’t have to deal with a default environment with long precompile times down the line.


That does it. Thanks!