# AMPL license activation

**URL:** <https://discuss.ampl.com/t/ampl-license-activation/1183>\
**Category:** Support\
**Created:** [August 19, 2024, 2:47pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183 "2024-08-19T14:47:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![LANIELSON\_ANDRADE\_SI](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/lanielson_andrade_si/32/814_2.png) [@LANIELSON\_ANDRADE\_SI](https://discuss.ampl.com/u/LANIELSON_ANDRADE_SI)\
**Post date:** [August 19, 2024, 2:47pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/1 "2024-08-19T14:47:34Z")

</div>

I downloaded the Knitro solver files. To use it, I need to activate the ampl license. However, I couldn’t activate the license and so I can’t use knitro. Can you help me?

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [August 19, 2024, 2:51pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/2 "2024-08-19T14:51:50Z")

</div>

Hi @LANIELSON_ANDRADE_SI,

Thank you for reaching out. Which error did you get when you tried to activate the license?

---

<div class="post-metadata">

**Author:** ![LANIELSON\_ANDRADE\_SI](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/lanielson_andrade_si/32/814_2.png) [@LANIELSON\_ANDRADE\_SI](https://discuss.ampl.com/u/LANIELSON_ANDRADE_SI)\
**Post date:** [August 19, 2024, 4:03pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/3 "2024-08-19T16:03:22Z")

</div>

The license has been activated, but I can’t use ‘knitro’ in my pyomo scrip in vscode. How can I proceed?

 ![license](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/c349bfe302f21f1c095db5ca0b9a9c72a4165a9a.png)

![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/d457a3654354474ed6e55c1a1df50372c9d116b4.png)

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [August 19, 2024, 4:07pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/4 "2024-08-19T16:07:57Z")

</div>

To use Knitro with Pyomo you should just need to pass the path to it to SolverFactory. Are you getting a license error when you try to use it?

You can also try with the modules for Python that also work with Pyomo: [AMPL Modules for Python — AMPL Resources](https://dev.ampl.com/ampl/python/modules.html#using-from-pyomo)

---

<div class="post-metadata">

**Author:** ![LANIELSON\_ANDRADE\_SI](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/lanielson_andrade_si/32/814_2.png) [@LANIELSON\_ANDRADE\_SI](https://discuss.ampl.com/u/LANIELSON_ANDRADE_SI)\
**Post date:** [August 19, 2024, 5:34pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/5 "2024-08-19T17:34:21Z")

</div>

Exactly, there seems to be a problem with the license:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/942a12c85ee9e4d1f03742b5e9a9ed09176fc045.png)

However, the license is activated and working. Please note:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/1c581e593d9d7f6560d3d7e764133ae503b0a0f2.png)

What could it be?

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [August 19, 2024, 5:42pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/6 "2024-08-19T17:42:03Z")

</div>

Could you please check the value of `os.envion["AMPL_LICFILE"]`? Somehow seems to have a different value than the one in `.bashrc`. Alternatively, you could also update the value in `.bashrc` to that one and move the license to the location where Knitro is looking for it.

---

<div class="post-metadata">

**Author:** ![LANIELSON\_ANDRADE\_SI](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/lanielson_andrade_si/32/814_2.png) [@LANIELSON\_ANDRADE\_SI](https://discuss.ampl.com/u/LANIELSON_ANDRADE_SI)\
**Post date:** [August 19, 2024, 6:13pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/7 "2024-08-19T18:13:10Z")

</div>

I changed the line  
export PATH=/opt/ampl.linux-intel64/:$PATH  
to  
export PATH=$PATH:"$HOME/.ampl/ampl.linux-intel64/”  
I thought that was the error, but it still doesn’t work.

![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/ad7cd0dea327535576d6f9997d0dec5e82b38c6f.png)

I updated bashrc after this change, but the error persists.

Error:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/48c646a5a052375bb5bb1875b1d05ab5e1f33266.png)

I’ve checked:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/1068671b3ae8db41d4e7fb083b2a4e2fe722bf3e.png)

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [August 19, 2024, 6:18pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/8 "2024-08-19T18:18:22Z")

</div>

Since `os.environ["AMPL_LICFILE]` is pointing to $HOME/.ampl/ampl.lic. Knitro will be looking for the license there. You may need to restart the notebook in order to load the new environment variable value in `.bashrc`.

---

<div class="post-metadata">

**Author:** ![LANIELSON\_ANDRADE\_SI](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/lanielson_andrade_si/32/814_2.png) [@LANIELSON\_ANDRADE\_SI](https://discuss.ampl.com/u/LANIELSON_ANDRADE_SI)\
**Post date:** [August 19, 2024, 7:14pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/9 "2024-08-19T19:14:31Z")

</div>

I restarted my PC and was able to use knitro:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/c22f39daf4d8f4d9bb1d9a21f3b195772321b082.png)

However, when trying to use a global solver, such as baron, the following error appeared:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/ampl/original/1X/12aca2b23f04ee6da1f7827eb1fd378409fabfcb.png)

Why were there no errors in the knitro, but there were in the baron?

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [August 19, 2024, 8:11pm UTC](https://discuss.ampl.com/t/ampl-license-activation/1183/10 "2024-08-19T20:11:30Z")

</div>

In the first argument of `SolverFactory` you should use “baronnl” instead of “baron” since Pyomo will try to use a bar file otherwise.

In case you used the python modules, the code for any solver would be:

```bash
!pip install amplpy pyomo -q
!python -m amplpy.modules install <solver-name> -q
!python -m amplpy.modules activate <license-uuid>

```

```python
from amplpy import modules
import pyomo.environ as pyo
solver_name = "<solver-name>"
solver = pyo.SolverFactory(solver_name+"nl", executable=modules.find(solver_name), solve_io="nl")

```
