Working with Julia packages
Julia packages are an organized set of ready—made functions, classes, and objects for solving various tasks. Julia packages can be installed using the Pkg package manager and used in your projects. If you need a clearer separation of packages into user and system packages, use EngeePkg.
In Engee Julia packages are also handled through the built-in Pkg package manager using two workspace tools. — command prompt
and script editor
.
When working with a large number of packages, it is convenient to use the script editor, which does not require reinitialization after calling Pkg. The command line is useful if you are more used to working with code outside the script editor interface and with a small number of packages.
| A detailed description of working with the Pkg package manager can be found in 2. Getting Started. |
The principle of working with packages
-
Find the exact name of the package you are interested in. The Julia ecosystem contains more than ten thousand packages registered in the general registry, which can make it very difficult to find the right package. To optimize your search, we recommend that you refer to the following sources:
-
Programming — section Engee with full documentation on Julia in Russian.
-
JuliaHub is a service for searching through all registered documentation of open source packages with the ability to sort by tags and keywords.
-
Julia Packages is an online resource designed to search, explore, and view Julia packages with the ability to customize filters by category, popularity, and dates.
-
Julia.jl is the main repository of packages for the Julia programming language. This repository is stored on the GitHub platform and contains many useful packages and tools developed by the community for working with the Julia language.
-
-
Choose a tool for working with packages — the command line or script editor, depending on your tasks.
-
Initialize working with packages in Julia by adding the Pkg package manager. The syntax for adding a manager differs depending on the selected tool.
-
Add packages using the command
addto your environment to use them in your project. The syntax for adding packages depends on the selected tool. -
Load a package into a namespace and access its specific elements using the operators
usingandimport. You can also add your own packages. -
If necessary, find out the package status via
statuscheck which packages are loaded into RAM Engee and delete unnecessary ones viaremoveorrm(the syntax depends on the selected tool).
Detailed information about working with packages is provided below.
Julia packages on the command line
To install a new package on the command line Engee, left-click in the code entry area and click the closing square bracket ]. This will switch the command line to work with the package manager. The row will change its appearance from engee> on pkg>:
pkg>
In the package manager mode, use the command add to add a package:
add Example
You can add multiple packages at the same time by listing their names separated by commas, for example:
add Example, Plots, Pluto
To delete a package, use the command remove or an abbreviated version of it rm:
remove Pluto
The result of package deletion
Updating `/user/.project/Project.toml`
[c3e4b0f8] - Pluto v0.19.38
Updating `/user/.project/Manifest.toml`
[5218b696] - Configurations v0.17.6
[e2d170a0] - DataValueInterfaces v1.0.0
[21656369] - ExpressionExplorer v1.0.0
[55351af7] - ExproniconLite v0.10.5
[fb4132e2] - FuzzyCompletions v0.5.3
[ac1192a8] - HypertextLiteral v0.9.5
[82899510] - IteratorInterfaceExtensions v1.0.0
[0e77f7df] - LazilyInitializedFields v1.2.2
[6c6e2e6c] - MIMEs v0.1.4
[36869731] - Malt v1.1.1
[99f44e22] - MsgPack v1.2.0
[c3e4b0f8] - Pluto v0.19.38
[91cefc8d] - PrecompileSignatures v3.0.3
[aea7be01] - PrecompileTools v1.2.0
[2792f1a3] - RegistryInstances v0.1.0
[3783bdb8] - TableTraits v1.0.1
[bd369af6] - Tables v1.10.0
[410a4b4d] - Tricks v0.1.6
If necessary, you can delete several packages at a time, listing their names separated by commas.:
remove Pluto, Plots, Example
An attempt to delete a non-existent package will return an error.:
_ Error output_
The following package names could not be resolved:
* Package name (not found in project or manifest)
To exit the package manager mode pkg> left-click on the code entry area and click Backspace. This will return you to the primary view of the command line. engee>.
|
Julia packages in the Script editor
To install a new package in an interactive script Engee, in the section with the code, import the Pkg with the command import Pkg, and then run the command Pkg.add("Package name"). For example, the section with the code for adding a package Example it will look like this:
import Pkg
Pkg.add("Example")
After pressing the Start button
The Pkg package manager will be imported on this section and the package will be installed. Example. Information about the package installation progress will be displayed automatically.:
Resolving package versions...
Installed Example ─ v0.5.3
Updating `/user/start/Project.toml`
[7876af07] + Example v0.5.3
Updating `/user/start/Manifest.toml`
[7876af07] + Example v0.5.3
As with the command line, you can add multiple packages at the same time by separating their names by commas and adding square brackets to create an array of strings, for example:
Pkg.add(["Example", "Plots"])
To delete a package, use the command rm:
Pkg.rm("Example")
To delete multiple packages at the same time, the names are separated by commas and square brackets.:
Pkg.rm(["Example", "Plots"])
Team remove it is not defined in the script editor, although it is used on the command line. An attempt to invoke the command in the editor will return an error.:
`UndefVarError: `remove` not defined`
| In the script editor, the name of the Pkg package manager and Julia package names are case-sensitive and must start with a capital letter, otherwise you will receive an error message. |
Package status
To find out which packages are installed and ready for use, open the command prompt and follow these steps:
-
Log in to the Pkg Package Manager via ].
-
Write a command
status:
pkg> status
After that, you will see a list of installed packages and their version.:
_ Package status output_
pkg> status
Status `/user/.project/Project.toml`
⌅ [c3fe647b] AbstractAlgebra v0.27.8
⌅ [7d9f7c33] Accessors v0.1.27
⌅ [79e6a3ab] Adapt v3.5.0
⌅ [91a5bcdd] Plots v1.36.1
⌃ [c3e4b0f8] Pluto v0.19.36
Symbols ⌃ and ⌅ This means that there are new versions for the packages.:
-
⌃— a newer version is available. -
⌅— there is a newer version, but there are compatibility conflicts with other packages.
You can also find out which packages are installed and ready for use through the script editor.:
-
Enter
import Pkgif you haven’t done this before. -
Enter
Pkg.status()to get the status of packages.
Downloading packages
In Julia, operators are used to download packages and provide access to their specific elements, such as functions, types, and variables. import and using:
-
using— used to load all exported names from the module and bind them to the current namespace. For example:using Statistics x = mean([1, 2, 3, 4, 5]) -
import— used to selectively import certain functions or variables from a module. Requires specifying the module name before the function or variable name. Therefore, a function or variable that is not explicitly imported will not be available in the current environment.Example:
import Statistics x = Statistics.mean([1, 2, 3, 4, 5])
Consider the advantages and limitations of the operators:
-
Advantage
using— convenience. The code becomes more succinct, and all functions and variables from modules are available in the current namespace. -
Disadvantage
using— useusingloading large modules with many functions and variables can affect performance and memory overflow. -
Disadvantage
using— name conflict.usingIt can cause name conflicts if multiple modules define functions or variables with the same name. -
Advantage
import— no name conflict. -
Advantage
import— Reduce compilation time by avoiding the need to compile unnecessary code. -
Disadvantage
import— complication of the code.
Thus, the operator using It is more suitable for small projects with an emphasis on convenience. Operator import It is more suitable for large projects with an emphasis on selectivity and control over memory usage.