Skip to content

"segmentation fault python3" error when trying to import scikit-learn #23830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EugenioBarbieriViale opened this issue Jul 4, 2022 · 10 comments · Fixed by #23833
Closed

"segmentation fault python3" error when trying to import scikit-learn #23830

EugenioBarbieriViale opened this issue Jul 4, 2022 · 10 comments · Fixed by #23833

Comments

@EugenioBarbieriViale
Copy link

Describe the bug

When I try to import scikit-learn, I get a segmentation error. All the other libraries I try to use work fine.

Steps/Code to Reproduce

First I installed it using pip3 install scikit-learn, then I tried pip3 install sklearn. Then I removed scikit-learn by typing pip3 uninstall scikit-learn and re-installed it with the command pip3 install -U scikit-learn. It still doesn't work.

Expected Results

The result I expected was that I could import the library with no problems

Actual Results

This is wat I get:

>>> import sklearn
[1]    6442 segmentation fault  python3`

In addition there is a pop-up that says: "Python quit unexpectedly."
The report:

Process:               Python [6516]
Path:                  /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python
Identifier:            Python
Version:               3.9.0 (3.9.0)
Code Type:             X86-64 (Native)
Parent Process:        zsh [6419]
Responsible:           Python [6516]
User ID:               501

Date/Time:             2022-07-04 20:45:17.706 +0200
OS Version:            Mac OS X 10.12.6 (16G2136)
Report Version:        12
Anonymous UUID:        93F73F8B-BF71-B52D-DDB7-DAB809F701A5

Sleep/Wake UUID:       21CB12E0-87EC-4B01-8A09-D2FEFCDE0F51

Time Awake Since Boot: 33000 seconds
Time Since Wake:       830 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

VM Regions Near 0:
--> 
    __TEXT                 000000010becf000-000000010bed0000 [    4K] r-x/rwx SM=COW  /Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

...

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 1
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 17978
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=309.7M resident=0K(0%) swapped_out_or_unallocated=309.7M(100%)
Writable regions: Total=161.4M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=161.4M(100%)
 
                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                    8K        2 
MALLOC                            44.1M       59 
MALLOC guard page                   16K        4 
MALLOC_LARGE (reserved)            384K        2         reserved VM address space (unallocated)
STACK GUARD                         12K        4 
Stack                             17.0M        4 
VM_ALLOCATE                       64.0M        3 
VM_ALLOCATE (reserved)            32.0M        2         reserved VM address space (unallocated)
__DATA                             9.9M      196 
__LINKEDIT                       134.8M      216 
__TEXT                           175.5M      181 
__UNICODE                          556K        2 
shared memory                       12K        4 
===========                     =======  ======= 
TOTAL                            478.2M      666 
TOTAL, minus reserved VM space   445.9M      666 

Model: MacBookAir3,2, BootROM 110.0.0.0.0, 2 processors, Intel Core 2 Duo, 2,13 GHz, 4 GB, SMC 1.66f61
Graphics: NVIDIA GeForce 320M, NVIDIA GeForce 320M, PCI, 256 MB
Memory Module: BANK 0/DIMM0, 2 GB, DDR3, 1067 MHz, 0x80CE, 0x4D34373142353237334348302D5946382020
Memory Module: BANK 1/DIMM0, 2 GB, DDR3, 1067 MHz, 0x80CE, 0x4D34373142353237334348302D5946382020
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0xD1), Broadcom BCM43xx 1.0 (5.106.98.102.30)
Bluetooth: Version 5.0.5f7, 3 services, 27 devices, 1 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
Serial ATA Device: APPLE SSD TS256C, 251 GB
USB Device: USB 2.0 Bus
USB Device: Built-in iSight
USB Device: USB 2.0 Bus
USB Device: Card Reader
USB Device: USB Bus
USB Device: BRCM2070 Hub
USB Device: Bluetooth USB Host Controller
USB Device: Apple Internal Keyboard / Trackpad
USB Device: USB Bus
Thunderbolt Bus: 

Versions

- OS: MacOs Sierra 10.12.6
- python3 version: 3.9.0
- pip3 version: 22.1.1
- scikit-learn version: 1.1.1
- numpy version: 1.23.0
- scipy version: 1.8.1
@thomasjpfan
Copy link
Member

I suspect it is because we set MACOSX_DEPLOYMENT_TARGET=10.13 when building the wheels, which is not compatible with 10.12. In #23833, I made the target 10.9, which should build a wheel that works on 10.12.

For testing, can you download this wheel file and run:

pip install scikit_learn-1.2.dev0-cp39-cp39-macosx_10_9_x86_64.whl

@thomasjpfan thomasjpfan added Build / CI and removed Needs Triage Issue requires triage labels Jul 4, 2022
@EugenioBarbieriViale
Copy link
Author

I uninstalled scikit-learn and then re-installed it in this way, but the result didn't change

@thomasjpfan
Copy link
Member

To capture the segfault, can you run:

lldb python -- -c "import sklearn"

which should bring you into a debugger. From there run "run":

(lldb) run

This should give you more information about the segfault.

@EugenioBarbieriViale
Copy link
Author

I got this error error: process exited with status -1 (cannot attach to process due to System Integrity Protection)

@thomasjpfan
Copy link
Member

Having the debugger blocked by System Integrity Protection is unfortunate. For debugging, can you try to import numpy and import scipy to see if they work?

How did you install Python?

Another option is to install Python with anaconda and install scikit-learn with conda.

@EugenioBarbieriViale
Copy link
Author

All other libraries work fine, included numpy and scipy. I think python was already installed

@thomasjpfan
Copy link
Member

I think python was already installed

Trying a different installation of Python is a way to narrow down the issue. Currently you have Python installed here:

/Library/Frameworks/Python.framework/Versions/3.9/Resources/Python.app/Contents/MacOS/Python

I'm trying to see if the issue still happens when using anaconda's Python.

@EugenioBarbieriViale
Copy link
Author

Any results?

@thomasjpfan
Copy link
Member

thomasjpfan commented Jul 7, 2022

I'm trying to see if the issue still happens when using anaconda's Python.

My comment in #23830 (comment) was to explain why I suggest installing Python with anaconda for debugging.

Can you to install Python with anaconda, install scikit-learn with anaconda's Python, and test it? I do not have access to a OSX machine running 10.12.6 for testing.

EDIT: I quick way to install conda's Python is to use miniconda

@EugenioBarbieriViale
Copy link
Author

I can't install miniconda since it's aviable only for macos version >=10.13. It would take hours to just download the anaconda file, so I think that I'm going to give up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants