In Pluto, when Using [pkg_name] fails to load a package it gives “Things you could try”.
The package [pkg_name].jl could not load because it failed to initialize.
That's not nice! Things you could try:
Restart the notebook.
Try a different Julia version.
Contact the developers of [pkg_name].jl about this error.
However I find the suggestions miss the often most basic ones, and can potentially point one off on a tangent. Despite now getting fairly familiar with Julia and Pkg, I still find the most common mistakes are actually:
Check the spelling
Check you’ve loaded the package (when in a project environment)
Any chance these could be added to the “Things to try” ?
Note: This is possibly/probably a request to one of the devs, but is the Julia Main or a Pkg error?
julia> using DatFrames
ERROR: ArgumentError: Package DatFrames not found in current path.
- Run `import Pkg; Pkg.add("DatFrames")` to install the DatFrames package.
whereas in Pluto:
Error message from Main
The package DatFrames.jl could not load because it failed to initialize.
That's not nice! Things you could try:
Restart the notebook.
Try a different Julia version.
Contact the developers of DatFrames.jl about this error.
You might find useful information in the package installation log:
So I assume you’re talking about Pluto here?
Btw Pkg already does what you suggests when installing (rather than loading) packages:
pkg> add DatFrames
ERROR: The following package names could not be resolved:
* DatFrames (not found in project, manifest or registry)
Suggestions: DataFrames GeoDataFrames Pathnames TSFrames DataFrameTools DataFramesMeta StanDataFrames TimeDataFrames NCDataFrame DateFormats TimeFrames DataTables DataGraphs DataValues DataFrameMacro
Thanks @nilshg. Yes indeed Pluto.
The suggestions when type during pkg.add is excellent… but one doesn’t get there when having forgotten to add the pkg first, which was my 2nd point.
So looks like it’s Pluto. I’ll raise a request there.
Well in Pluto that doesn’t make a lot of sense as there is no add (packages are automatically added on using by default). That would of course make it more useful if the error on using would warn about typos.
Ah… I found it didn’t automatically add the packages I needed in a project environment. But quickly checking a MWE I find it does.
begin
using Pkg
Pkg.activate("Env_MWE") # set up new env
# Pkg.add("Plots") # NOT needed
using Plots # load (not add) any package
plot([1,2], [3,4]) # Works!
end
Must have been the JuliaHub environment I was in.
Thanks for the clarification!
Huh, interesting - my recollection was that when you do using Pkg in a Pluto notebook it disables the Pluto package manager and you’re back to plain Pkg, but maybe that has changed, I haven’t used Pluto in a while.
BTW: Pkg.add() is required when adding packages to a project environment and/or using a non-default package direct from github.
From what I can see, not using Pkg.add() in a project environment but only using [pkg_name] will auto-load (default) packages BUT it’ll load them in the Julia generic entries instead of the specific environment.
begin
using Pkg
Pkg.activate("Env_MWE2")
# Pkg.add("Plots") # try with and without this
using Plots
end
plot([1,2], [3,4]) # still works!
but then having NOT used Pkg.add() to add Plots
Pkg.rm("Plots")
results in
The following package names could not be resolved:
* Plots (not found in project or manifest)
Suggestions: Colors
As when Plots had been added with Pkg.add("Plots") it adds -a dedicated version- to the project directory, and subsequently removes fine.