ModuleNotFoundError: No module named 'sksurv' in python
Asked Answered
W

1

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.

Whaley answered 25/10, 2020 at 1:17 Comment(8)
What is "everything"? Are you certain it's installed?Immigration
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++ compileWhaley
You shouldn't need to install the dependencies separately, when you install it, it'll automatically install required dependencies. It says here that you need to install gcc also. Did you do that?Immigration
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__='..............Whaley
Try installing CMake first, then rerun pip install scikit-survival. osqp requires CMake so that's probably what is causing the error.Immigration
It worked! I do not know to thank you. I am about to cry of happinessWhaley
Okay, I will post an answer so others who run into this problem can know it workedImmigration
It would be great. Thank you much.Whaley
I
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
Immigration answered 25/10, 2020 at 1:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.