6

I am trying to run survival analysis in python (pycharm) in linux, here is a part of the code

import numpy as np
import matplotlib.pyplot as plt
#matplotlib inline
import pandas as pd

from sklearn.impute import SimpleImputer
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import train_test_split

from sksurv.datasets import load_flchain
from sksurv.linear_model import CoxPHSurvivalAnalysis

I get the error "ModuleNotFoundError: No module named 'sksurv'", I tried everything, but nothing works.

  • 2
    What is "everything"? Are you certain it's installed? – marsnebulasoup Oct 25 '20 at 01:25
  • I installed Requirements Python 3.5 or later cvxpy cvxopt joblib numexpr numpy 1.12 or later osqp pandas 0.21 or later scikit-learn 0.22 or 0.23 scipy 1.0 or later C/C++ compile –  Oct 25 '20 at 01:27
  • 1
    You shouldn't need to install the dependencies separately, when you install it, it'll automatically install required dependencies. It says [here](https://scikit-survival.readthedocs.io/en/latest/install.html) that you need to install gcc also. Did you do that? – marsnebulasoup Oct 25 '20 at 01:29
  • I installed gcc, do i need to install "pip install scikit-survival", I get the error ERROR: Command errored out with exit status 1: /home/myname/PycharmProjects/survival/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-usdsompl/osqp/setup.py'"'"'; __file__='.............. –  Oct 25 '20 at 01:40
  • 1
    Try installing [CMake](https://cmake.org/download/) first, then rerun `pip install scikit-survival`. `osqp` requires CMake so that's probably what is causing the error. – marsnebulasoup Oct 25 '20 at 01:43
  • It worked! I do not know to thank you. I am about to cry of happiness –  Oct 25 '20 at 01:46
  • 1
    Okay, I will post an answer so others who run into this problem can know it worked – marsnebulasoup Oct 25 '20 at 01:46
  • It would be great. Thank you much. –  Oct 25 '20 at 01:47

1 Answers1

3

The required dependencies for scikit-survival,

  • cvxpy

  • cvxopt

  • joblib

  • numexpr

  • numpy 1.12 or later

  • osqp

  • pandas 0.21 or later

  • scikit-learn 0.22

  • scipy 1.0 or later

...will be automatically installed by pip when you run:

pip install scikit-survival

However, one module in particular, osqp, has CMake as one of its dependencies. If you don't have CMake installed, pip install scikit-survival will throw an error and the installation will fail.

You can download CMake for your OS at cmake.org/download

After CMake has installed, you should be able to successfully run

pip install scikit-survival

Notes:

  • GCC needs to be installed also
  • scikit-survival works with Python 3.5 or higher
  • More information is available in the docs
marsnebulasoup
  • 2,530
  • 2
  • 16
  • 37