I have more than a hundred packages installed. But Pkg.installed() only lists some 40 due to the size of the terminal window. How can I see all installed packages?
Also, how can I have the installed packages printed alphabetically using Pkg.installed()? It’s hard to pick ham from peas.
It takes more than 5 minutes on my machine for Pkg.installed() to return. Is this normal?
Is there a way to see all registered Julia packages on the METADATA git page: https://github.com/JuliaLang/METADATA.jl. The last 277 packages are not see-able on that page.
I use a package which is registered with METADATA. But I don’t use its tagged version, since it’s too old. I use the development version that I checked out from its git repo. However, each time when I Pkg.update(), the tagged version is installed automatically and overrides the version I intend to use. This really drive me nuts as I have to manually Pkg.rm the tagged version. Is there a way to avoid this?
I’ll try and answer these questions, though I’m no expert.
Pkg.installed() returns a Dict, so you could pass it to the sort function and also write a loop to see the list a few lines at a time, or just list all the keys in alphabetical order
showall(sort(collect(keys(Pkg.installed()))))
It will probably be O(n) on the number of packages since it’s a file-system operation to look through all packages on disk
git clone https://github.com/JuliaLang/METADATA.jl and then view the file locally. The limitation on what you see on the github page is imposed by github.
Try Pkg.pin to pin the package to the version you want, or Pkg.checkout to always stay on the latest version.
sort(collect(Pkg.installed())) will print them in sorted order. show(STDOUT, "text/plain", sort(collect(Pkg.installed()))) will print them all, but it would be nice to have something better by default.
Are you using Windows? Julia’s package system currently uses lots of little files in the METADATA repo to store metadata, which is pretty slow on Windows (it was even worse before we switched to libgit in Julia 0.5). At some point we are hoping to switch to a new package metadata system that will eliminate this problem (https://github.com/JuliaLang/Juleps/blob/master/Pkg3.md).
Yes. It’ll be more convenient if something like show(STDOUT, "text/plain", sort(collect(Pkg.installed()))) can be set as default or at least be able to be opt for.
No. I’m on Ubuntu. I think it’s more or less because my machine is old and was running something else at the same time, though it’s definitely on the scale of minutes rather than seconds.
If it refers to getting the names of the installed packages in alphabetical order without using the deprecated package, then you can use something like
julia> io = IOBuffer();
julia> using Pkg; Pkg.status(; io)
julia> text = String(take!(io));
julia> lines = split(text, '\n')[2:end-1]
5-element Array{SubString{String},1}:
" [336ed68f] CSV v0.8.2"
" [a93c6f00] DataFrames v0.22.2"
" [59287772] Formatting v0.4.2"
" [713c75ef] Franklin v0.10.21"
" [38e38edf] GLM v1.3.11"
julia> lines_without_id = [l[14:end] for l in lines]
5-element Array{SubString{String},1}:
"CSV v0.8.2"
"DataFrames v0.22.2"
"Formatting v0.4.2"
"Franklin v0.10.21"
"GLM v1.3.11"
this assumes quite a lot about the appearance of the output of Pkg.status. So, not very reliable, but could be useful for scripts.
I’m going to clean things up (I have rejoined Julia after a long hiatus and didn’t realize about the environment system, so I’ve made a big mess of my packages). Here’s how I’ve made a list and plan to retrieve it later:
# make list of packages:
using Pkg
deps = [pair.second for pair in Pkg.dependencies()]
direct_deps = filter(p -> p.is_direct_dep, deps)
[(x.name, x.version) for x in direct_deps]
pkg_name_version = [(x.name, x.version) for x in direct_deps]
pkg_list = [x.name for x in direct_deps]
# save list for later:
outfile = "julia-dependencies-2021-04-27.txt"
open(outfile, "w") do f
for i in pkg_list
println(f, i)
end
end
# retrieve list and add packages
using Pkg
infile = "julia-dependencies-2021-04-27.txt"
open(infile, "r") do file
for line in eachline(file)
Pkg.add(line)
end
end