Can't load package (StatsBase) in Jupyter notebook but can in REPL

I have a fresh installation of julia-1.6.5 on an ubuntu 18.04 box. I added a number of packages and in the REPL, I can

julia> using StatsBase
[ Info: Precompiling StatsBase [2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91]

Success. But the same thing in a jupyter notebook (which I have to use) results in:

┌ Info: Precompiling StatsBase [2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91]
└ @ Base loading.jl:1342
┌ Warning: Package ChangesOfVariables does not have ChainRulesCore in its dependencies:
│ - If you have ChangesOfVariables checked out for development and have
│   added ChainRulesCore as a dependency but haven't updated your primary
│   environment's manifest file, try `Pkg.resolve()`.
│ - Otherwise you may need to report an issue with ChangesOfVariables
└ Loading ChainRulesCore into ChangesOfVariables from project dependency, future warnings for ChangesOfVariables are suppressed.
┌ Warning: The call to compilecache failed to create a usable precompiled cache file for LogExpFunctions [2ab3a3ac-af41-5b50-aa03-7779005ae688]
│   exception = Required dependency ChangesOfVariables [9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0] failed to load from a cache file.
└ @ Base loading.jl:1055
┌ Warning: Package ChangesOfVariables does not have ChainRulesCore in its dependencies:
│ - If you have ChangesOfVariables checked out for development and have
│   added ChainRulesCore as a dependency but haven't updated your primary
│   environment's manifest file, try `Pkg.resolve()`.
│ - Otherwise you may need to report an issue with ChangesOfVariables
└ Loading ChainRulesCore into ChangesOfVariables from project dependency, future warnings for ChangesOfVariables are suppressed.
ERROR: LoadError: UndefVarError: StatisticalModel not defined
Stacktrace:
 [1] include
   @ ./Base.jl:384 [inlined]
 [2] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
   @ Base ./loading.jl:1235
 [3] top-level scope
   @ none:1
 [4] eval
   @ ./boot.jl:360 [inlined]
 [5] eval(x::Expr)
   @ Base.MainInclude ./client.jl:446
 [6] top-level scope
   @ none:1
in expression starting at /home/me/.julia/packages/StatsBase/pJqvO/src/StatsBase.jl:1

I am definitely using the julia-1.6.5 kernel.

Anyone know how I can fix or get around this? Am I doing something wrong?

Regarding the warnings, I have added LogExpFunctions, ChangesOfVariables, and ChainRulesCore, and loaded them (using) in the REPL too. I tried the Pkg.resolve().

Are you adding the packages in a local project.toml, or are they in your v1.6 toml file?

Make sure you do import Pkg; Pkg.activate(".") before adding packages and try again.

No, I was just adding them in the “global” environment. I am trying to make what you suggest work, but is that necessary? If so, can you tell me why? Thanks.

I don’t know. I wonder if IJulia is using some environment that’s different than the main one and isn’t inheriting the global environment for some reason.

I could be wrong though.

It definitely is inheriting because I can Pkg.add() a package from the REPL in the global environment and in the jupyter notebook the package becomes “available” (even though it can’t precompile it).

This seems to have worked. If anyone can help me understand, that would still be appreciated. Thank you.

Hi everyone I am having the same problem as rwgardner but the solution proposed by @pdeffebach is not working for me. Do you have any clue on how to solve this issue?
If it matters I am using DrWatson and thus a toml file.

PS: I have been using julia in the last six months, including the StatsBase package, without any problem. It arouse out of the blue today