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

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

问题描述

我安装了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兼容.有时,它有助于安装软件包的master分支,而不是最后一个标记的发行版.在我的机器上,我必须做

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字符串":

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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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