How to use package in Julia without importing it?

import will bring a module into scope without any of its exported names. You can still use qualified names to reference names within the imported module:

import Plots
Plots.plot(rand(5,5))

To avoid using the qualified name, you can create a binding to a new name:

const plot_from_plots = Plots.plot

According to the Julia website you should be able to do:

using Plots: plot

Which will only bring plot() in scope


See Module aliasing in Julia for how to create an alias for the method


In addition to the other suggestions; I wrote a package (ImportMacros) which lets you import functions with other names without bringing anything else into scope:

julia> using ImportMacros

julia> @import Plots.plot as plt

julia> plt
plot (generic function with 3 methods)

so Plots.plot is available as plt, yet Plots is undefined:

julia> Plots
ERROR: UndefVarError: Plots not defined

Tags:

Julia