45

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.

2
  • pkgs["Datetime"] does nothing for me: Julia version 0.5.2. Commented May 20, 2017 at 3:14
  • this is deprecated now (2025) Commented Aug 29 at 9:16

6 Answers 6

32

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
Sign up to request clarification or add additional context in comments.

13 Comments

In the REPL you can use a faster way, by typing TAB after the left parenthesis: julia> Pkg.installed(\tab
Not that I know about.
@jangorecki The OP was using Pkg.installed. In version 1.0.0, I think you may need using Pkg first.
@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.
@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!
|
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

4 Comments

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?
Oh interesting. That is not a method of that package. I am on 0.4dev so maybe it is a new function.
@JamesonQuinn, indeed since Julia 1.x Pkg needs to be imported.
julia> Pkg.status("LinearAlgebra") Status C:\Users\joe\.julia\environments\v1.5\Project.toml [37e2e46d] LinearAlgebra But it doesn't tell me the version.
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.

Comments

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

1 Comment

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
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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.