List of downloaded / imported packages in Julia

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

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

It seems that whos() contains relevant information (names and whether it is a module or not). Is it possible to capture the output of whos() in a variable?

+10
reproducible-research julia-lang julia
source share
6 answers
 using Lazy children(m::Module) = @>> names(m, true) map(x->m.(x)) filter(x->isa(x, Module) && x ≠ m) 

children(Main) then provide you with a list of loadable modules.


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

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

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

+4
source share

Use names , for example

 julia> using JuMP julia> using Gurobi julia> names(Main) 13-element Array{Symbol,1}: :Calculus :ans :JuMP :DualNumbers :Graphs :DataStructures :ReverseDiffSparse :MathProgSolverInterface :Base :MathProgBase :Core :Gurobi :Main 
+6
source share

The suggested answers do not work with Julia 1.0 and therefore, here is the version of Julia 1.0:

 filter((x) -> typeof(eval(x)) <: Module && x ≠ :Main, names(Main,imported=true)) 
+1
source share

The answer above does not work as before in Julia 0.5. It works in many cases, for example:

 children(SIUnits) -> SIUnits.ShortUnits 

But most packages (which I use) do not actually define submodules. I find this useful for debugging, in the Julia command line version and in another minute of excellent Juno IDE:

 loadedmodules() = filter(names(Main, false)) do n isa(eval(n), Module) && n ≠ Main end 
0
source share

I use,

 using Pkg function magic() println("Julia " * string(VERSION)) for (key, version)sort(collect(Pkg.installed())) try isa(eval(Symbol(key)), Module) && println(key * " " * string(version)) end end end 
0
source share

So this is not so nice with a single line, but: it works on v1.0 , and allows a simple recursive search to show all loaded modules:

 function children(m::Module) ns = names(m, imported=true, all=true) ms = [] for n in ns if n != nameof(m) try x = Core.eval(m, n) x isa Module && push!(ms, x) catch end end end ms end function children_deep(m::Module) cs = children(m) for c in cs cs = union(cs, children(c)) end cs end 

Then:

 julia> children_deep(Main) 43-element Array{Any,1}: Base Core InteractiveUtils Base.BaseDocs Base.Broadcast Base.Cartesian Base.Checked Core.Compiler.CoreDocs ⋮ Base.Sys Base.Threads Base.Unicode Base.__toplevel__ Core.Compiler Core.IR Core.Intrinsics Main 
0
source share

All Articles