Get path to julia install?

I’ve been doing some memory profiling using --track-allocation=all. This puts output files in the same location as the source files, including in the base julia install, e.g. base/multidimensional.jl.27819.mem. Now I know where these files are on my own machine, but I’d like to write some generic scripts to profile my code, and then read the profiles. Coverage.jl handles most of this nicely, but needs to be passed the directories to search for *.mem files. So my question is: how do I (within a Julia script) get the path to the julia installation directory (containing base/ and stdlib/)? For bonus points, is there a way to get the equivalent of ~/.julia if it’s not in the default location?

1 Like

One way that might work is to follow this StackOverflow answer: How to find the path of a package in Julia? - Stack Overflow. The function suggested there

julia> module_file(modu) = String(first(methods(getfield(modu, :eval))).file)

doesn’t help if I try to find the directory for Base

julia> module_file(Base)

but for something in the standard library, e.g. REPL, it does give a path which I could then use to figure out the install directory I wanted. Surely there must be an easier way though?

1 Like

Maybe you can find the directory relative to Sys.BINDIR, which is the full path to the directory containing the julia executable:

joinpath(Sys.BINDIR, "..", "share", "julia")

Perhaps you can extract from DEPOT_PATH. See Constants · The Julia Language



Thanks @greg_plowman! You’ve answered the question I asked. It turns out for my actual use case, DEPOT_PATH is even better - it looks like that’s the set of almost all directories where source files might be (it looks to me like it doesn’t include packages added with Pkg.develop() though), so I can just pass that (plus the directory with the source for my package) to Coverage.analyze_malloc() instead of having to handle base/stdlib and ~/.julia separately. Awesome!

Edit: I ended up needing [x for x in DEPOT_PATH if isdir(x)] because .../julia-1.6.1/usr/local/share/julia didn’t actually exist.

1 Like

Packages that are Pkg.develop ed are either in DEPOT_PATH/dev so this should be dealt with you solution already or they are in where JULIA_PKG_DEVDIR points to. See 3. Managing Packages · Pkg.jl.

1 Like