Julia: missing packages still print out "use `Pkg.add()`"

Created on 10 Aug 2018  路  7Comments  路  Source: JuliaLang/julia

See

julia> using StatsBase
ERROR: ArgumentError: Package StatsBase not found in current path:
- Run `Pkg.add("StatsBase")` to install the StatsBase package.

Stacktrace:
 [1] require(::Module, ::Symbol) at ./loading.jl:817
julia> Pkg.add("StatsBase")
ERROR: UndefVarError: Pkg not defined
Stacktrace:
 [1] top-level scope at none:0
julia> versioninfo()
Julia Version 1.0.0
Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

Most helpful comment

Can we just put import Pkg in a default startup.jl file?

All 7 comments

You need to load Pkg first; import Pkg. I guess we can update the suggestion in the error message

Thanks. That loads Pkg3 right? I fixed the issue by ] and typing add StatsBase.

I agree a better error message will be more helpful for newcomers (and even some intermediate users like me).

If you don't pointing out where this can be done, I'll be happy to do a PR.

That loads Pkg3 right?

Yes, Pkg3 was renamed to Pkg.

I'll be happy to do a PR.

Sure, here you go!

diff --git a/base/loading.jl b/base/loading.jl
index 7feb1cdd26..f55f75498d 100644
--- a/base/loading.jl
+++ b/base/loading.jl
@@ -816,7 +816,7 @@ function require(into::Module, mod::Symbol)
         if where.uuid === nothing
             throw(ArgumentError("""
                 Package $mod not found in current path:
-                - Run `Pkg.add($(repr(String(mod))))` to install the $mod package.
+                - Run `import Pkg; Pkg.add($(repr(String(mod))))` to install the $mod package.
                 """))
         else
             s = """

Thanks, PR done. so for future reference loading.jl is mainly used for package managing code?

This is why I had Pkg exported by InteractiveUtils; we're going to keep getting this bug report.

It would be good if we could add this back but fix the previous two problems:

  • Not introduce a cycle in the stdlib dependencies
  • Be able to load another package called Pkg so we can still develop it.

Can we just put import Pkg in a default startup.jl file?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  路  3Comments

ararslan picture ararslan  路  3Comments

yurivish picture yurivish  路  3Comments

musm picture musm  路  3Comments

omus picture omus  路  3Comments