44

How can I get the version number for a specific package?

The obvious way is to get the dictionary with all installed packages, and then filter for the one of interest:

pkgs = Pkg.installed();
pkgs["Datetime"]

Getting the list of all installed packages is very slow though, especially if there are many packages.

Julian
  • 1,271
  • 2
  • 12
  • 17

6 Answers6

31

EDIT: For Julia version 1.1+

Use the Pkg REPL notation:

] status                        # Show every installed package version
] status pkgName                # Show the specific version of the package
] status pkgName1 pkgName2      # Show the named packages. You can continue the list.

The ] enters the Pkg REPL, so you basically write status ...

So in your case, write after entering the Pkg REPL:

status DataFrame

Or use the object-oriented approach (NB: Here you don't enter the Pkg REPL, i.e. DON'T use ]:

Pkg.status("DataFrame")

EDIT: For Julia version 1.0

Pkg.installed seems to have "regressed" with the new package system. There are no arguments for Pkg.installed. So, the OP's original method seems to be about the best you can do at the moment.

pkgs = Pkg.installed();
pkgs["Datetime"]

EDIT: For Julia version upto 0.6.4

You can pass a string to Pkg.installed. For example:

pkgs = Pkg.installed("JuMP")

I often check available calling arguments with methods. For example:

julia> methods(Pkg.installed)
# 2 methods for generic function "installed":
installed() at pkg/pkg.jl:122
installed(pkg::AbstractString) at pkg/pkg.jl:129

or

julia> Pkg.installed |> methods
# 2 methods for generic function "installed":
installed() at pkg/pkg.jl:122
installed(pkg::AbstractString) at pkg/pkg.jl:129
DisabledWhale
  • 771
  • 1
  • 7
  • 15
rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
  • 2
    In the REPL you can use a faster way, by typing TAB after the left parenthesis: ``julia> Pkg.installed(\tab`` – ivarne Sep 03 '14 at 13:21
  • @ivarne Cool! Didn't know that. Thanks! Any REPL sorcery for `methodswith`? – rickhg12hs Sep 03 '14 at 15:16
  • 1
    Not that I know about. – ivarne Sep 04 '14 at 08:06
  • I get ``installed(pkg::AbstractString)`` as the second method. – PatrickT May 20 '17 at 03:16
  • I am getting `ERROR: MethodError: no method matching installed(::String)`. Could be the answer updated to 1.0.0? Hopefully now api will not be changing that often. – jangorecki Oct 03 '18 at 10:21
  • 1
    @jangorecki The OP was using `Pkg.installed`. In version 1.0.0, I think you may need `using Pkg` first. – rickhg12hs Nov 17 '18 at 16:54
  • 1
    @jangorecki ... and I think `Pkg.installed` in version 1.0.0 and up may have a different meaning. Perhaps the new meaning is "packages directly installed by the user, but not dependencies" rather than "all installed packages". IDK for sure, I'm still on v0.6.4. – rickhg12hs Nov 17 '18 at 17:21
  • @JamesonQuinn indeed, no trace of `Pkg.installed` in the [Pkg API reference](https://julialang.github.io/Pkg.jl/stable/api/) – Pierre H. Sep 17 '19 at 08:14
  • all of this prints out the output, how would go go about storing the ouput into a variable – Flying Turtle Jun 08 '20 at 03:16
  • `Warning: Pkg.installed() is deprecated` For Julia Version 1.5.2 (at least). See https://stackoverflow.com/a/25635704/10156184 – DisabledWhale Dec 10 '20 at 20:21
  • 1
    @DisabledWhale I'm not currently a `Julia` user. I've reassigned this answer to Community wiki. Please feel free to update the answer for the latest `Julia` info. Thanks! – rickhg12hs Dec 12 '20 at 10:45
  • 1
    Sorry - I did not think of editing! All the best and thanks for pointing out :) – DisabledWhale Dec 13 '20 at 17:04
  • Note that you can `using`/`import` packages that are installed not in the current `activate`d environment, but further up in `LOAD_PATH`. Is there a way to get the version of all of these packages without needing to activate the environments separately? – Gus Dec 11 '21 at 17:24
13

I would try Pkg.status("PackageName")

This will print out a little blurb giving the package name.

Here is an example

julia> Pkg.status("QuantEcon")
 - QuantEcon                     0.0.1              master
spencerlyon2
  • 9,476
  • 4
  • 30
  • 39
  • `Pkg.status("QuantEcon")` gives me `ERROR: 'status' has no method matching status(::ASCIIString)` in julia 0.3. Is the method part of a particular package? – Julian Sep 03 '14 at 03:35
  • 1
    Oh interesting. That is not a method of that package. I am on 0.4dev so maybe it is a new function. – spencerlyon2 Sep 03 '14 at 23:37
  • 3
    @JamesonQuinn, indeed since Julia 1.x `Pkg` needs to be imported. – Pierre H. Sep 17 '19 at 08:08
  • 1
    julia> Pkg.status("LinearAlgebra") Status `C:\Users\joe\.julia\environments\v1.5\Project.toml` [37e2e46d] LinearAlgebra But it doesn't tell me the version. – skan Oct 26 '20 at 19:54
9

In Julia 1.1 you can use

(v1.1) pkg> status "name_of_the_package"

to find the version of any package in a given environment.

sbac
  • 1,897
  • 1
  • 18
  • 31
2

In order to look of a version of an indirectly included package (e.g. top-level project includes Module A which depends on Module B, where you need to know info about Module B), you have to pull the info either from the Manifest.toml directly, or you have to bring in the Context object in from Pkg.

Below is done with Julia 1.3.1 ... there may be changes to Pkg's internals since then.

using Pkg
using UUIDs

ctx = Pkg.Operations.Context()

# Get the version of CSV.jl
version = ctx.env.manifest[UUID("336ed68f-0bac-5ca0-87d4-7b16caf5d00b")].version
if version <= v"0.5.24"
    # handle some uniqueness about the specific version of CSV.jl here
end

UPDATE: Or without a UUID and just the package name (thanks @HHFox):

using Pkg

pkg_name = "Observables"
m = Pkg.Operations.Context().env.manifest

v = m[findfirst(v->v.name == pkg_name, m)].version

or to do the same with the Manifest.toml

using Pkg

# given the path to the Manifest.toml file...
manifest_dict = Pkg.TOML.parsefile(manifest_path)

# look for a named package like `CSV`
package_dict = manifest_dict[package_name][1]
@show package_dict
Nathan Musoke
  • 166
  • 1
  • 12
phyatt
  • 18,472
  • 5
  • 61
  • 80
  • I like this solution. Here is a version that matches the name rather than the UUID `using Pkg; m = Pkg.Operations.Context().env.manifest; v = m[findfirst(v->v.name=="Observables", m)].version` – HHFox Jun 17 '21 at 16:16
0

Well this didn't print well in the comment section... Here is a version that matches the name rather than the UUID

using Pkg

m = Pkg.Operations.Context().env.manifest
v = m[findfirst(v -> v.name == "CSV", m)].version
HHFox
  • 311
  • 2
  • 7
0

For packages which are dependencies of the specified packages in the project file one can use status -m <packageName> or shorter st -m <packageName> in package mode (After ]`).

For a full list, just use st -m.

This is an extension to https://stackoverflow.com/a/25641957.

Royi
  • 4,640
  • 6
  • 46
  • 64