Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 318
Julian Avatar asked Aug 29 '14 20:08

Julian


2 Answers

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))
like image 74
Przemyslaw Szufel Avatar answered Oct 08 '22 04:10

Przemyslaw Szufel


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.

like image 24
one-more-minute Avatar answered Oct 08 '22 06:10

one-more-minute