How to test if package is installed



What’s the recommended API for testing if a package (which may not be registed) is installed? I have seen two versions floating around:

"somepackage" ∈ keys(Pkg.installed())



The second one feels hackish. First I thought checking Pkg.installed("somepackage") but that can return an error for unregistered, uninstalled packages.

(This is for use in .juliarc.jl, when running different versions.)


The second one is very similar to how Pkg itself does it, so I would not say it’s hackish (unless you believe the approach of Pkg itself to be hackish). If you want to match exactly how Pkg determines if a package is installed, use

isinstalled(pkg::AbstractString) =
    pkg != "METADATA" && pkg != "REQUIRE" && pkg[1] != '.' &&, pkg)


Pkg doesn’t have the most useful conception of what “installed” means at the moment. What are you trying to accomplish? Modules can be used from anywhere on LOAD_PATH without Pkg knowing anything about them.


basically, something like this in .juliarc:

if (SomePackage is installed) && (VERSION >= v"0.6-")
           import SomePackage

ie using a package but not causing an error if it is not available.


Can’t you just use a try catch?