# Using JuMP in Python Environment

**URL:** <https://discourse.julialang.org/t/using-jump-in-python-environment/61165>\
**Category:** Optimization (Mathematical)\
**Tags:** pycall, jump, python\
**Created:** [May 14, 2021, 2:57pm UTC](https://discourse.julialang.org/t/using-jump-in-python-environment/61165 "2021-05-14T14:57:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [May 14, 2021, 2:57pm UTC](https://discourse.julialang.org/t/using-jump-in-python-environment/61165/1 "2021-05-14T14:57:23Z")

</div>

I am trying to embed JuMP-based Julia script into a Python-based computing framework using PyCall. However, I am facing problems when I define JuMP variable as

```julia
from julia import Ipopt
from julia.JuMP import Model 
from julia.JuMP import add_constraint
from julia.JuMP import add_variable

m = Model(Ipopt.Optimizer)
add_variable(m, x[1:2]

```

results in following error message

```julia
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-13-61e874849be7> in <module>
      1 m = Model(Ipopt.Optimizer)
----> 2 add_variable(m, x[1:2])

NameError: name 'x' is not defined

```

Is there any document that I can refer to for troubleshooting?

---

<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:** [May 16, 2021, 9:53pm UTC](https://discourse.julialang.org/t/using-jump-in-python-environment/61165/2 "2021-05-16T21:53:06Z")

</div>

`add_variable` and `add_constraint` are not the same as `@variable` and `@constraint`. You need figure out how to call Julia macros from Python (if it’s even possible).

A better question is: why do you want to call JuMP from Python? This is probably more hassle than it’s worth. Use [https://www.pyomo.org](https://www.pyomo.org) instead.

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [May 28, 2021, 1:52am UTC](https://discourse.julialang.org/t/using-jump-in-python-environment/61165/3 "2021-05-28T01:52:48Z")

</div>

I managed this by wrapping JuMP model into a Julia function. It can also dump out the variable values in Python.

One reason, I initially developed JuMP models, and I want to focus to improve the JuMP model rather than recoding in Pyomo. The second reason, there are subprocedures dependent on Python libraries for other tasks, and the entire framework is intended to be directed in a Python environment. Thanks
