# LoadError: UndefVarError: @variables not defined

**URL:** <https://discourse.julialang.org/t/loaderror-undefvarerror-variables-not-defined/71170>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 8, 2021, 7:45pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-variables-not-defined/71170 "2021-11-08T19:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goh/32/28770_2.png) [@GoH](https://discourse.julialang.org/u/GoH)\
**Post date:** [November 8, 2021, 7:45pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-variables-not-defined/71170/1 "2021-11-08T19:45:12Z")

</div>

I got the error ‘LoadError: UndefVarError: @variables not defined’ while testing the code provided by ModelingToolkits webpage [Solving Nonlinear Systems with NLsolve · ModelingToolkit.jl](https://docs.juliahub.com/ModelingToolkit/Qmdqu/3.12.0/tutorials/nonlinear/#usage)

Here is the code:

```julia
begin
	using ModelingToolkit
	using JuMP
	
	@variables x y z
	@parameters σ ρ β
	
	# Define a nonlinear system
	eqs = [0 ~ σ*(y-x),
	       0 ~ x*(ρ-z)-y,
	       0 ~ x*y - β*z]
	ns = NonlinearSystem(eqs, [x,y,z], [σ,ρ,β])
	nlsys_func = generate_function(ns)[2] # second is the inplace version
end

```

Much appreciated if someone could help.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 8, 2021, 7:59pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-variables-not-defined/71170/2 "2021-11-08T19:59:11Z")

</div>

It’s probably because ModelingToolkit and JuMP both export `@variables`. They aren’t the same thing, so you need to prefix which one you want. (Did it show a warning talking about multiple packages exporting the same name?)

```julia
begin
	using ModelingToolkit
	using JuMP
	
	ModelingToolKit.@variables x y z
	@parameters σ ρ β
	

```

It seems like you don’t need JuMP here, so you should probably just remove it. Then you won’t hit this problem.

---

<div class="post-metadata">

**Author:** ![Pangoraw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pangoraw/32/24719_2.png) [@Pangoraw](https://discourse.julialang.org/u/Pangoraw)\
**Post date:** [November 8, 2021, 9:24pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-variables-not-defined/71170/3 "2021-11-08T21:24:08Z")

</div>

It can also be caused by the fact that the using statement and the macro calls are in the same expression (the begin block). Because macros are evaluated before the expression code is run this could explain that it is not yet defined. You can try to move it in multiple blocks:

```julia
begin
    using ModelingToolkit
end

begin
    ModelingToolkit.@variables x y z
    # the rest of the code...
end

```
