Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a package in Julia 1.0 (UndefVarError: Pkg not defined)

Tags:

I installed Julia 1.0, and want to make a simple plot. The first step is to type this on Julia:

Pkg.add("PyPlot") 

However, an error occurs:

ERROR: UndefVarError: Pkg not defined. 

The same thing happens when I type:

Pkg.status() 

What's the best way to install a package in Julia? I use MacOS.

like image 414
Jimmy Li Avatar asked Aug 10 '18 20:08

Jimmy Li


People also ask

Where are packages installed in Julia?

Your package requirements are in the file ~/. julia/v0.

How do you get out of PKG in Julia?

Enter the Pkg REPL by pressing ] from the Julia REPL. To get back to the Julia REPL, press backspace or ^C.


1 Answers

In Julia 1.0, there are two ways to install a package. First, you can do

using Pkg Pkg.add("Packagename") 

Second, you can use the Pkg REPL mode by pressing ] (similar to ?, help mode, and ;, shell mode):

(v1.0) pkg> add Packagename 

You can find more information here: https://docs.julialang.org/en/stable/stdlib/Pkg/# and here (live demo): https://youtu.be/GBi__3nF-rM?t=28m1s

Julia 1.0 is brand new. It has been released a few days ago, so some packages aren't yet compatible with 1.0. Sometimes it helps to install the master branch of a package instead of the last tagged release. On my machine I had to do

(v1.0) pkg> add LaTeXStrings#master (v1.0) pkg> add PyPlot 

to get PyPlot to work. Hope this helps.

UPDATE: LaTeXStrings has been updated (tagged). The first line above is therefore not necessary anymore.

UPDATE2: Another (shorter) live demo can be found here: https://www.youtube.com/watch?v=76KL8aSz0Sg

UPDATE3: There is a third way of interacting with the package manager, namely "pkg strings":

using Pkg pkg"add Packagename" 
like image 73
carstenbauer Avatar answered Oct 27 '22 17:10

carstenbauer