Julian
Julian

Reputation: 1311

Determine version of a specific package

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.

Upvotes: 45

Views: 24794

Answers (6)

phyatt
phyatt

Reputation: 19152

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

Upvotes: 2

Royi
Royi

Reputation: 4963

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.

Upvotes: 0

HHFox
HHFox

Reputation: 329

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

Upvotes: 0

rickhg12hs
rickhg12hs

Reputation: 11942

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

Upvotes: 32

sbac
sbac

Reputation: 2081

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.

Upvotes: 9

spencerlyon2
spencerlyon2

Reputation: 9686

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

Upvotes: 13

Related Questions