xiaodai
xiaodai

Reputation: 16004

Julia: is there a function to obtain the version number of a package?

I see that Pkg.status("PkgName") prints something like this Pkg v0.12.0 to the REPL.

I tried to @edit Pkg.status("Pkgname") but encountered some macro code that I don't understand.

What's the easiest way to obtain the version number of a package in the current activate environment?

Upvotes: 3

Views: 851

Answers (3)

Ian Fiske
Ian Fiske

Reputation: 10602

It's convenient to use the widely-used Compat.jl package. It has a pkgversion function:

using Compat
using PkgName

pkgversion(PkgName)

Upvotes: 0

Andrej Oskin
Andrej Oskin

Reputation: 2332

Currently you can use Pkg.dependencies() to get all information about all packages, as it was discussed here. For example

using Pkg

julia> filter(x-> x.second.name == "Crayons", Pkg.dependencies()) |> x -> first(x)[2].version   
v"4.0.1"

Upvotes: 3

Fredrik Bagge
Fredrik Bagge

Reputation: 1381

Pkg.installed() does give you the version of all installed packages as version strings, but it is deprecated and is likely to be removed in future versions of julia

julia> Pkg.installed()
┌ Warning: Pkg.installed() is deprecated
└ @ Pkg ~/julia/usr/share/julia/stdlib/v1.5/Pkg/src/Pkg.jl:561
Dict{String,VersionNumber} with 81 entries:
  "Interact"                    => v"0.10.3"
  "ForwardDiff"                 => v"0.10.12"
  "UMAP"                        => v"0.1.6"
  "Juno"                        => v"0.8.2"

Upvotes: 3

Related Questions