juliareproducible-research

List of loaded/imported packages in Julia


How can I get a list of imported/used packages of a Julia session?

Pkg.status() list all installed packages. I'm interested in the ones that that were imported/loaded via using ... or import ...

It seems that whos() contains the relevant information (the names and whether it is a module or not). Can the output of whos() be captured in a variable?


Solution

  • using Lazy
    children(m::Module) =
      @>> names(m, true) map(x->m.(x)) filter(x->isa(x, Module) && x ≠ m)
    

    children(Main) will then give you a list of modules currently loaded.


    Edit: I used Lazy.jl here for the thrush macro (@>>), but you can rewrite it without easily enough:

    children(m::Module) =
      filter(x->isa(x, Module) && x ≠ m, map(x->m.(x), names(m, true)))
    

    Alternatively you could add && x ≠ Lazy to the filter to avoid including it.