sebp / scikit-survival

Survival analysis built on top of scikit-learn
GNU General Public License v3.0
1.14k stars 216 forks source link

Numpy error for CoxPHSurvivalAnalysis #492

Closed manas-kohli closed 1 week ago

manas-kohli commented 2 weeks ago

Hello!

This may sound very elementary but I'm trying to follow along the tutorial for scikit-survival. So far things have been working fine but when I try to specifically import the CoxPHSurvivalAnalysis function, I'm getting an error:

from sksurv.linear_model import CoxPHSurvivalAnalysis

Traceback (most recent call last):
  File "__init__.cython-30.pxd", line 1024, in numpy.import_array
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.2.4\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mkohli\anaconda3\envs\Conda\Lib\site-packages\sksurv\linear_model\__init__.py", line 2, in <module>
    from .coxnet import CoxnetSurvivalAnalysis  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mkohli\anaconda3\envs\Conda\Lib\site-packages\sksurv\linear_model\coxnet.py", line 25, in <module>
    from ._coxnet import call_fit_coxnet
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.2.4\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "sksurv\\linear_model\\_coxnet.pyx", line 16, in init sksurv.linear_model._coxnet
  File "__init__.cython-30.pxd", line 1026, in numpy.import_array
ImportError: numpy._core.multiarray failed to import

This seems like a numpy versioning error which is a bit strange since all the other featuers in sksurv are working fine for import. I'm using PyCharms and anaconda to manage my packages. My current numpy version is 1.26.4 and my scikit-survival package version is 0.23.1

Is there something stupid I'm doing? So far in the first tutorial, every other import has worked fine. Do I need to specifically use numpy 2.0? Any help would be appreciated with this. Thanks in advance!

sebp commented 1 week ago

How did you install scikit-survival? Via pip, anaconda, or something else?

Can you post the output of the following command please:

import sksurv; sksurv.show_versions()
manas-kohli commented 1 week ago

I installed scikit-survival with anaconda and I realised the numpy version wasn't letting me update beyond 1.26.4. I just got frustated and made a new environment and numpy is now 2.1.3 and it works fine. I'll close this issue