Distributions package not recognized after installation on JuliaPro


#1

After installing the Distributions.jl package in JuliaPro, the commands do not seem to be recognized.


#2

Silly question, but did you import it via using Distributions before you tried Normal()?


#3

I used Pkj.add(“Distributions”). Did I do it wrong?


#4

That’s necessary but not sufficient. Pkg.add() just downloads the code to your system so that it’s available. To use it within a script or the REPL, you need to import the functions via using. See https://docs.julialang.org/en/stable/manual/modules/ for more details:

The statement using Lib means that a module called Lib will be available for resolving names as needed. When a global variable is encountered that has no definition in the current module, the system will search for it among variables exported by Lib and import it if it is found there. This means that all uses of that global within the current module will resolve to the definition of that variable in Lib.


#5

Did you use the “using Distributions” clause before calling Normal() or not?


#6

Thank you for pointing out the error of my ways. I am an experienced MATLAB programmer trying to see what Julia can offer. Appreciate your help.


#7

No worries. The languages are similar but there are definitely some gotchas.


#8

Just a note to add:

Pkg.add("pkg") needs to be issued only once in a Julia installation, while using pkg is required on each script/REPL usage whenever you want the functionality of the package exposed…


#9

Well to be fair, MATLAB is probably the only language where every package in the directory is automatically imported instead of having to manually import the packages you want to use. I am pretty sure that we all agree that MATLAB’s style there causes major namespacing issues in any sufficiently large package system.