Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions pyomo/solvers/plugins/solvers/KNITROAMPL.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# software. This software is distributed under the 3-clause BSD License.
# ____________________________________________________________________________________
import logging
import os

from pyomo.common import Executable
from pyomo.common.collections import Bunch
Expand Down Expand Up @@ -64,17 +65,25 @@ def __init__(self, **kwds):
self._capabilities.sos2 = False

def _default_executable(self):
try:
# If knitro Python package is available, use the executable it contains
import knitro
executable = None
knitrodir = os.environ.get('KNITRODIR')
if knitrodir:
knitroampl_path = pathlib.Path(knitrodir) / 'knitroampl' / 'knitroampl'
executable = Executable(str(knitroampl_path))
if not executable:
try:
# If knitro Python package is available, use the executable it contains
import knitro

package_knitroampl_path = (
pathlib.Path(knitro.__file__).resolve().parent
/ 'knitroampl'
/ 'knitroampl'
)
executable = Executable(str(package_knitroampl_path))
except ModuleNotFoundError:
package_knitroampl_path = (
pathlib.Path(knitro.__file__).resolve().parent
/ 'knitroampl'
/ 'knitroampl'
)
executable = Executable(str(package_knitroampl_path))
except ModuleNotFoundError:
pass
if not executable:
# Otherwise, search usual path list
executable = Executable('knitroampl')
if not executable:
Expand Down
Loading