如何在 Julia 1.0 中安装软件包(UndefVarError: Pkg not defined) [英] How to install a package in Julia 1.0 (UndefVarError: Pkg not defined)

查看:52
本文介绍了如何在 Julia 1.0 中安装软件包(UndefVarError: Pkg not defined)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了 Julia 1.0,并想制作一个简单的情节.第一步是在 Julia 上输入:

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

Pkg.add("PyPlot")

但是,出现错误:

ERROR: UndefVarError: Pkg not defined.

当我输入时也会发生同样的事情:

The same thing happens when I type:

Pkg.status()

在 Julia 中安装软件包的最佳方式是什么?我使用 MacOS.

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

推荐答案

在 Julia 1.0 中,有两种安装包的方法.首先,你可以这样做

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

using Pkg
Pkg.add("Packagename")

其次,可以通过按]来使用Pkg REPL模式(类似于?,帮助模式,;,shell模式):

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

(v1.0) pkg> add Packagename

您可以在此处找到更多信息:https://docs.julialang.org/en/stable/stdlib/Pkg/#在这里(现场演示):https://youtu.be/GBi__3nF-rM?t=28m1s

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 是全新的.前几天已经发布了,所以有些包还不兼容1.0.有时它有助于安装包的主分支而不是最后一个标记的版本.在我的机器上我必须这样做

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

让 PyPlot 工作.希望这会有所帮助.

to get PyPlot to work. Hope this helps.

更新: LaTeXStrings 已更新(标记).因此,上面的第一行不再需要了.

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

UPDATE2: 可以在此处找到另一个(较短的)现场演示:https://www.youtube.com/watch?v=76KL8aSz0Sg

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

UPDATE3:还有第三种与包管理器交互的方式,即pkg strings":

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

using Pkg
pkg"add Packagename"

这篇关于如何在 Julia 1.0 中安装软件包(UndefVarError: Pkg not defined)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆