Determine version of a specific package
Asked Answered
A

6

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.

Argot answered 3/9, 2014 at 2:54 Comment(1)
pkgs["Datetime"] does nothing for me: Julia version 0.5.2.Convexoconcave
R
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
Regardless answered 3/9, 2014 at 2:54 Comment(13)
In the REPL you can use a faster way, by typing TAB after the left parenthesis: julia> Pkg.installed(\tabAlimentation
@Alimentation Cool! Didn't know that. Thanks! Any REPL sorcery for methodswith?Regardless
Not that I know about.Alimentation
I get installed(pkg::AbstractString) as the second method.Convexoconcave
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.Vaginitis
@Vaginitis The OP was using Pkg.installed. In version 1.0.0, I think you may need using Pkg first.Regardless
@Vaginitis ... 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.Regardless
@JamesonQuinn indeed, no trace of Pkg.installed in the Pkg API referenceOza
all of this prints out the output, how would go go about storing the ouput into a variableCockerel
Warning: Pkg.installed() is deprecated For Julia Version 1.5.2 (at least). See https://mcmap.net/q/377268/-determine-version-of-a-specific-packageWilke
@Wilke 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!Regardless
Sorry - I did not think of editing! All the best and thanks for pointing out :)Wilke
Note that you can using/import packages that are installed not in the current activated 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?Orthographize
C
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
Corticate answered 3/9, 2014 at 3:16 Comment(4)
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?Argot
Oh interesting. That is not a method of that package. I am on 0.4dev so maybe it is a new function.Corticate
@JamesonQuinn, indeed since Julia 1.x Pkg needs to be imported.Oza
julia> Pkg.status("LinearAlgebra") Status C:\Users\joe\.julia\environments\v1.5\Project.toml [37e2e46d] LinearAlgebra But it doesn't tell me the version.Boykin
P
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.

Pitiful answered 3/7, 2019 at 22:28 Comment(0)
G
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
Gonsalve answered 15/12, 2020 at 16:52 Comment(1)
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)].versionAgnail
A
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
Agnail answered 17/6, 2021 at 16:22 Comment(0)
H
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.

Hornpipe answered 29/11, 2022 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.