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

**URL:** <https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095>\
**Category:** General Usage\
**Created:** [February 25, 2022, 8:08pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095 "2022-02-25T20:08:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwgardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rwgardner/32/10344_2.png) [@rwgardner](https://discourse.julialang.org/u/rwgardner)\
**Post date:** [February 25, 2022, 8:08pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/1 "2022-02-25T20:08:07Z")

</div>

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
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:

```julia
┌ 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().

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 25, 2022, 8:16pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/2 "2022-02-25T20:16:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rwgardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rwgardner/32/10344_2.png) [@rwgardner](https://discourse.julialang.org/u/rwgardner)\
**Post date:** [February 25, 2022, 8:43pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/3 "2022-02-25T20:43:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 25, 2022, 9:44pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/4 "2022-02-25T21:44:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rwgardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rwgardner/32/10344_2.png) [@rwgardner](https://discourse.julialang.org/u/rwgardner)\
**Post date:** [February 25, 2022, 10:16pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/5 "2022-02-25T22:16:16Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![rwgardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rwgardner/32/10344_2.png) [@rwgardner](https://discourse.julialang.org/u/rwgardner)\
**Post date:** [February 25, 2022, 11:36pm UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/6 "2022-02-25T23:36:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![el\_cechin](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@el\_cechin](https://discourse.julialang.org/u/el_cechin)\
**Post date:** [April 14, 2022, 10:34am UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/7 "2022-04-14T10:34:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![el\_cechin](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@el\_cechin](https://discourse.julialang.org/u/el_cechin)\
**Post date:** [April 14, 2022, 11:41am UTC](https://discourse.julialang.org/t/cant-load-package-statsbase-in-jupyter-notebook-but-can-in-repl/77095/8 "2022-04-14T11:41:10Z")

</div>

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
