On writing modules using functions from other packages

If you add the dependencies (Images, here) to the main environment, that should work.

This is a reasonable solution while the number of packages is not too great (I have Plots and a bunch of other packages installed in the main environment, exactly for wanting to use them eventually in other places).

Other alternatives can be to have one package with your inhouse functions.

Or, depending on what you are doing, you can create an environment just for running your module, using something like:

import Pkg
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
Pkg.activate(temp=true)
Pkg.add(name="Images")
push!(LOAD_PATH, "/home/bruno/Documents/juliautils/mymodules")
using MyModule

The second line avoids the registry to be updated and thus the subsequent “adding” of the package Images is fast. This is practical, actually, but it prints a bunch of stuff to the screen (maybe there is an option to Pkg to work silently).

1 Like