diff --git a/amplpy/ampl.py b/amplpy/ampl.py index 0a5e37e..b0c48ae 100644 --- a/amplpy/ampl.py +++ b/amplpy/ampl.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import os from numbers import Real from .errorhandler import ErrorHandler @@ -100,6 +101,11 @@ def __init__(self, environment=None, langext=None): try: if environment is None: self._impl = amplpython.AMPL() + if os.name == "nt": + # Workaround for Windows issue with environment variables + ampl_libpath = os.environ.get("ampl_libpath", "") + if ampl_libpath: + self._impl.setOption("ampl_libpath", ampl_libpath) else: self._impl = amplpython.AMPL(environment._impl) except RuntimeError as exp: diff --git a/amplpy/environment.py b/amplpy/environment.py index 5ee7f58..2a6a3cc 100644 --- a/amplpy/environment.py +++ b/amplpy/environment.py @@ -2,6 +2,7 @@ from .iterators import EnvIterator from .base import BaseClass from . import amplpython +import os class Environment(BaseClass): @@ -24,9 +25,13 @@ def __init__(self, binary_directory=None, binary_name=None): binary_directory = "" if binary_name is None: binary_name = "" - super(Environment, self).__init__( - amplpython.Environment(binary_directory, binary_name) - ) + _impl = amplpython.Environment(binary_directory, binary_name) + if os.name == "nt": + # Workaround for Windows issue with environment variables + ampl_libpath = os.environ.get("ampl_libpath", "") + if ampl_libpath: + _impl.put("ampl_libpath", ampl_libpath) + super(Environment, self).__init__(_impl) def __iter__(self): return EnvIterator(self._impl)