99
1010from .juliainfo import JuliaInfo
1111from .options import parse_jl_options
12- from .utils import is_windows
12+ from .utils import is_apple , is_windows
1313
1414logger = getLogger ("julia" )
1515
3131
3232def setup_libjulia (libjulia ):
3333 # Store the running interpreter reference so we can start using it via self.call
34- libjulia .jl_ .argtypes = [c_void_p ]
35- libjulia .jl_ .restype = None
34+ try :
35+ jl_ = libjulia .jl_
36+ except AttributeError :
37+ pass
38+ else :
39+ jl_ .argtypes = [c_void_p ]
40+ jl_ .restype = None
3641
3742 # Set the return types of some of the bridge functions in ctypes terminology
3843 libjulia .jl_eval_string .argtypes = [c_char_p ]
@@ -211,14 +216,14 @@ def __init__(self, libjulia_path, bindir, sysimage):
211216 if sys .version_info >= (2 , 7 , 13 ) and sys .version_info < (2 , 7 , 14 ):
212217 libjulia_path = libjulia_path .encode ("ascii" )
213218
214- with self ._windows_pathhack ():
219+ with self ._pathhack ():
215220 self .libjulia = ctypes .PyDLL (libjulia_path , ctypes .RTLD_GLOBAL )
216221
217222 setup_libjulia (self .libjulia )
218223
219224 @contextmanager
220- def _windows_pathhack (self ):
221- if not is_windows :
225+ def _pathhack (self ):
226+ if not is_windows and not is_apple :
222227 yield
223228 return
224229 # Using `os.chdir` as a workaround for an error in Windows
@@ -228,6 +233,8 @@ def _windows_pathhack(self):
228233 # is reported to work by many users:
229234 # https://github.com/JuliaPy/pyjulia/issues/67
230235 # https://github.com/JuliaPy/pyjulia/pull/367
236+ # Using this workaround for Julia >= 1.6 in macOS for now:
237+ # https://github.com/JuliaLang/julia/issues/40246
231238 cwd = os .getcwd ()
232239 try :
233240 os .chdir (os .path .dirname (self .libjulia_path ))
@@ -321,7 +328,7 @@ def init_julia(self, options=None):
321328 logger .debug ("argv[%d] = %r" , i , argv [i ])
322329
323330 logger .debug ("calling jl_init_with_image(%s, %s)" , jl_init_path , sysimage )
324- with self ._windows_pathhack ():
331+ with self ._pathhack ():
325332 self .jl_init_with_image (
326333 jl_init_path .encode ("utf-8" ), sysimage .encode ("utf-8" )
327334 )
0 commit comments