# "Packaging" dependencies into a sysimage

**URL:** <https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548>\
**Category:** General Usage\
**Created:** [March 24, 2023, 8:15am UTC](https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548 "2023-03-24T08:15:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sstroemer](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Post date:** [March 24, 2023, 8:15am UTC](https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548/1 "2023-03-24T08:15:03Z")

</div>

Based on the [tutorial of PackageCompiler.jl](https://julialang.github.io/PackageCompiler.jl/dev/sysimages.html), I am using the following to create a sysimage: `julia --project=. _create_sysimage.jl`. That file contains:

`_create_sysimage.jl`:

```julia
import Pkg
Pkg.add("PackageCompiler")
Pkg.add("Example")

import PackageCompiler

PackageCompiler.create_sysimage(
    ["Example"];
    sysimage_path="ExampleSysimagePrecompile.so",
    precompile_execution_file="_precompile_execution.jl"
)

```

and

`_precompile_execution.jl`:

```julia
import Example
Example.hello("somestring")

```

If I now try to use that sysimage, by calling

```julia
julia -JExampleSysimagePrecompile.so -e 'import Example; Example.hello("friend")'

```

it does not find `Example`:

```julia
ERROR: ArgumentError: Package Example not found in current path, maybe you meant `import/using .Example`.

```

* * *

Now I thought the sysimage to be a way to “package” the current state of my Julia session - which would include the package `Example`, that I am also explicitly passing to the `packages` argument of `create_sysimage(...)` - which apparently is not the case.

Running

```julia
julia --project=. -JExampleSysimagePrecompile.so -e 'import Example; Example.hello("friend")'

```

instead (which loads the temporary project, that `Pkg.add(...)` installed `Example` into), works. But why doesn’t the first one work too?

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [March 24, 2023, 12:31pm UTC](https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548/2 "2023-03-24T12:31:27Z")

</div>

I think doing `import .Example` should work, and actually the binding `Example` is already present when you load your sysimage, so importing is superfluous.

---

<div class="post-metadata">

**Author:** ![sstroemer](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Post date:** [March 24, 2023, 5:21pm UTC](https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548/3 "2023-03-24T17:21:50Z")

</div>

> [@rfourquet](#):
>
> […] actually the binding `Example` is already present when you load your sysimage, so importing is superfluous.

That makes a lot of sense, and that’s the main thing I was missing (I kinda just stuck to the Manual, and didn’t really think that through).

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [April 3, 2023, 1:18pm UTC](https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548/4 "2023-04-03T13:18:27Z")

</div>

Facing the same confusion - is there really no way we can use plain `import Example` (without the dot?)

Motivation: It would for sure simplify the code if we could use the same import statements when not using sysimage and when using sysimage

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [April 3, 2023, 1:29pm UTC](https://discourse.julialang.org/t/packaging-dependencies-into-a-sysimage/96548/5 "2023-04-03T13:29:50Z")

</div>

AFAIU you can use a plain `import Example` (without the dot), but then you also need to activate the project that lists `Example` in its dependencies.
