JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
810 stars 64 forks source link

[BUG] Hard crash due to Mac System Integrity Protection (SIP) Security Protocol Activation #531

Open ev-watson opened 3 months ago

ev-watson commented 3 months ago

Affects: PythonCall

Describe the bug Setting the PYTHON_JULIACALL_HANDLE_SIGNALS environment variable manually and then importing juliacall triggers the disk security protocol on MacOS

Meanwhile just importing juliacall works fine

ANY VERSIONS

Reproduce script:

import os

os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes")

import juliacall

For clarity: importing juliacall works fine, but if you set environment variable first, it triggers SIP

Your system Please provide detailed information about your system:

Additional context First seen at https://github.com/MilesCranmer/PySR/issues/682

MilesCranmer commented 3 months ago

@cjdoris wondering if you have any guesses for this one?

@ev-watson could you also provide detailed info about your Python installation, such as how you installed it, and what version number it is? (I think you might have shared this in the other thread, so maybe just copy it over)

MilesCranmer commented 3 months ago

Also, could you try installing juliacall in a fresh environment, and seeing if it still has the crash? Unfortunately I can't find any way to reproduce this so will be relying on your executions here.

ev-watson commented 3 months ago

This project I am doing through PyCharm, i have it make its own virtual environment and so thats how i have it done, it does not use conda, python version 3.9.6, this could be a PyCharm issue, maybe it does not have permissions

Different crash in fresh new python environment not through pycharm, python version 3.12.3, juliacall version 0.9.21 script:

import os

os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes")

import juliacall

command:

python -m trace -t testing.py

Traceback:

 --- modulename: __init__, funcname: __getitem__
__init__.py(397):         func = self._FuncPtr((name_or_ordinal, self))
__init__.py(398):         if not isinstance(name_or_ordinal, int):
__init__.py(399):             func.__name__ = name_or_ordinal
__init__.py(400):         return func
__init__.py(393):         setattr(self, name, func)
__init__.py(394):         return func
__init__.py(186):     jl_parse_opts.argtypes = [c.c_void_p, c.c_void_p]
__init__.py(187):     jl_parse_opts.restype = None
__init__.py(188):     jl_parse_opts(c.pointer(argc), c.pointer(argv))
__init__.py(189):     assert argc.value == 0
__init__.py(192):     try:
__init__.py(193):         jl_init = lib.jl_init_with_image__threading
 --- modulename: __init__, funcname: __getattr__
__init__.py(390):         if name.startswith('__') and name.endswith('__'):
__init__.py(392):         func = self.__getitem__(name)
 --- modulename: __init__, funcname: __getitem__
__init__.py(397):         func = self._FuncPtr((name_or_ordinal, self))
__init__.py(398):         if not isinstance(name_or_ordinal, int):
__init__.py(399):             func.__name__ = name_or_ordinal
__init__.py(400):         return func
__init__.py(393):         setattr(self, name, func)
__init__.py(394):         return func
__init__.py(196):     jl_init.argtypes = [c.c_char_p, c.c_char_p]
__init__.py(197):     jl_init.restype = None
__init__.py(198):     jl_init(
__init__.py(199):         (default_bindir if bindir is None else bindir).encode('utf8'),
__init__.py(200):         None if sysimg is None else sysimg.encode('utf8'),
__init__.py(198):     jl_init(
ERROR: could not load library "libjulia.1.dylib"
dlopen(libjulia.1.dylib, 0x0001): tried: 'libjulia.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibjulia.1.dylib' (no such file), '/Applications/Julia-1.7.app/Contents/Resources/julia/lib/julia/libjulia.1.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/bin/../lib/libjulia.1.dylib' (no such file), '/usr/lib/libjulia.1.dylib' (no such file, not in dyld cache), 'libjulia.1.dylib' (no such file), '/usr/local/lib/libjulia.1.dylib' (no such file), '/usr/lib/libjulia.1.dylib' (no such file, not in dyld cache)