官术网_书友最值得收藏!

Packages

Most of the standard library in Julia (can be found in /share/julia/base relative to where Julia was installed) is written in Julia itself. The rest of Julia's code ecosystem is contained in packages that are simply Git repositories. They are most often authored by external contributors, and already provide functionality for such diverse disciplines such as bioinformatics, chemistry, cosmology, finance, linguistics, machine learning, mathematics, statistics, and high-performance computing. A searchable package list can be found at http://pkg.julialang.org/. Official Julia packages are registered in the METADATA.jl file in the Julia Git repository, available on GitHub at https://github.com/JuliaLang/METADATA.jl.

Julia's installation contains a built-in package manager Pkg for installing additional Julia packages written in Julia. The downloaded packages are stored in a cache ready to be used by Julia given by Pkg.dir(), which are located at c:\users\username\.julia\vn.m\.cache, /home/$USER/.julia/vn.m/.cache, or ~/.julia/vn.m/.cache. If you want to check which packages are installed, run the Pkg.status() command in the Julia REPL, to get a list of packages with their versions, as shown in the following screenshot:

Packages

Packages list

The Pkg.installed() command gives you the same information, but in a dictionary form and is usable in code. Version and dependency management is handled automatically by Pkg. Different versions of Julia can coexist with incompatible packages, each version has its own package cache.

Tip

If you get an error with Pkg.status() such as ErrorException("Unable to read directory METADATA."), issue a Pkg.init() command to create the package repository folders, and clone METADATA from Git. If the problem is not easy to find or the cache becomes corrupted somehow, you can just delete the .julia folder, enter Pkg.init(), and start with an empty cache. Then, add the packages you need.

Adding a new package

Before adding a new package, it is always a good idea to update your package database for the already installed packages with the Pkg.update()command. Then, add a new package by issuing the Pkg.add("PackageName") command, and execute using PackageName in code or in the REPL. For example, to add 2D plotting capabilities, install the Winston package with Pkg.add("Winston "). To make a graph of 100 random numbers between 0 and 1, execute the following commands:

using Winston
plot(rand(100))

The rand(100) function is an array with 100 random numbers. This produces the following output:

Adding a new package

A plot of white noise with Winston

After installing a new Julia version, update all the installed packages by running Pkg.update() in the REPL. For more detailed information, you can refer to http://docs.julialang.org/en/latest/manual/packages/.

主站蜘蛛池模板: 柳江县| 连南| 道真| 邵武市| 翁牛特旗| 鹿泉市| 万安县| 策勒县| 类乌齐县| 池州市| 颍上县| 灯塔市| 兴安盟| 邹城市| 赣州市| 临湘市| 合川市| 阳江市| 年辖:市辖区| 梅河口市| 杭锦后旗| 宁夏| 克什克腾旗| 宜黄县| 晋州市| 刚察县| 兴化市| 玉林市| 延长县| 永和县| 鄱阳县| 冀州市| 浮山县| 林口县| 新绛县| 商水县| 黄大仙区| 贺兰县| 阳泉市| 云阳县| 乌恰县|