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 Pkg. |
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 — Engee section with full Julia documentation 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 package repository 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
add
command to your environment to use them in your project. The syntax for adding packages depends on the selected tool. -
Upload a package to a namespace and access its specific elements using the
using
andimport
operators. You can also add your own packages. -
If necessary, find out the package status via
status
, check which packages are loaded into the Engee RAM and delete unnecessary ones viaremove
orrm
(the syntax depends on the selected tool).
Detailed information about working with packages is provided below.
Julia packages on the command line
To install the new package on the Engee command line, 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 string will change its appearance from engee>
to pkg>
:
pkg>
In package manager mode, we use the add
command 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 remove a package, use the remove
command or its abbreviated version 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 command line view engee> .
|
Julia packages in the Script editor
To install a new package in the interactive Engee script, in the code section, 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 the Example
package 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 'Example` package will be installed. 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"])
The rm
command is used to delete the package.:
Pkg.rm("Example")
To delete multiple packages at the same time, the names are separated by commas and square brackets.:
Pkg.rm(["Example", "Plots"])
The remove
command 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 begin 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 ].
-
Enter the
status
command:
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
The characters ⌃
and ⌅
mean that there are new versions for the packages.:
-
⌃
— a newer version is available. -
⌅
— a newer version is available, 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 Pkg' if you haven’t done so before.
-
Enter
Pkg.status()
to get the status of the packages.
Downloading packages
In Julia, the import
and using
operators are used to download packages and provide access to their specific elements, such as functions, types, and variables:
-
'using' — is 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
is 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:
-
The advantage of
using
is convenience. The code becomes more succinct, and all functions and variables from modules are available in the current namespace. -
The disadvantage of
using
is that usingusing
to load large modules with many functions and variables can affect performance and memory overflows. -
The disadvantage of
using
is the name conflict.using
can cause name conflicts if multiple modules define functions or variables with the same name. -
The advantage of
import
is that there is no name conflict. -
The advantage of
import
is the reduction of compilation time, avoiding the need to compile unnecessary code. -
The disadvantage of
import
is the complexity of the code.
Thus, the using
operator is more suitable for small projects with an emphasis on convenience. The import
operator is more suitable for large projects with an emphasis on selectivity and control over memory usage.