How to wrap using JuMP inside a function

I want to place “using JuMP” inside a function as follows

function test()

    using JuMP
    ...
end

However, it gives an error syntax: "using" expression not at top level, is there a way to work around it?

you need to make a module instead

Why do you need to do this?

2 Likes

Here you might find your answer: https://docs.julialang.org/en/v1/manual/faq/index.html#Can-I-use-using-or-import-inside-a-function?-1

4 Likes