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?
The proposed answers do not work with Julia 1.0 and hence here is a Julia 1.0 version:
filter((x) -> typeof(eval(x)) <: Module && x ≠ :Main, names(Main,imported=true))
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.
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