Skip to content

Commit

Permalink
Add workaround for Windows issue with environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fdabrandao committed Dec 26, 2023
1 parent 7453907 commit 30ffcaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions amplpy/ampl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys
import os
from numbers import Real

from .errorhandler import ErrorHandler
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions amplpy/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .iterators import EnvIterator
from .base import BaseClass
from . import amplpython
import os


class Environment(BaseClass):
Expand All @@ -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)
Expand Down

0 comments on commit 30ffcaf

Please sign in to comment.