ImportError with scikit-learn/sklearn in a Django app

I created simple Django project and one app inside, in that I need scikit-learn/sklearn library, I successfully installed it and I can see it using pip list command. But when I running application it shows that ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory. How can solve this, I think this is system library. Please give me solution for the same
for this lines I need scikit-learn

with open('trained_model.pkl', 'rb') as model_file:
    loaded_model = pickle.load(model_file) 

(when I take one simple python file without creating any project/app , Code run successfully, no any issue with scikit-lean or any other library, I can perform my task easily, But when I run this code in my project only then this problem encounters)
Replit Profile: https://replit.com/@punampanchal

Hey @punampanchal, welcome to the forums!

Can you please provide a link to the Repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

Yes, Please find the repl link below
https://replit.com/@punampanchal/MachineLearningProject
Also I have attached full Traceback of error for your reference

python3 manage.py runserver 0.0.0.0:3000
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
    self.check(display_num_errors=True)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
    all_issues = checks.run_checks(
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 416, in check
    for pattern in self.url_patterns:
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 602, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/urls/resolvers.py", line 595, in urlconf_module
    return import_module(self.urlconf_name)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/runner/MachineLearningProject/django_project/urls.py", line 21, in <module>
    path('', include('bank_customer_churn.urls')),
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
    urlconf_module = import_module(urlconf_module)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/runner/MachineLearningProject/bank_customer_churn/urls.py", line 2, in <module>
    from . import views
  File "/home/runner/MachineLearningProject/bank_customer_churn/views.py", line 2, in <module>
    import sklearn
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/sklearn/__init__.py", line 83, in <module>
    from .base import clone
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/sklearn/base.py", line 19, in <module>
    from .utils import _IS_32BIT
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 15, in <module>
    from scipy.sparse import issparse
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/scipy/sparse/__init__.py", line 267, in <module>
    from ._csr import *
  File "/home/runner/MachineLearningProject/venv/lib/python3.8/site-packages/scipy/sparse/_csr.py", line 10, in <module>
    from ._sparsetools import (csr_tocsc, csr_tobsr, csr_count_blocks,
ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory
1 Like

This is the important line.

Here you could run:

sed -i 's/];/  pkgs.stdenv.cc.cc.lib\
  &/' replit.nix
1 Like

No, It is not worked.
some changes reflected in replit.nix file. but while running application, same error (ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory)coming.

this is my replit.nix file

{ pkgs }: {
  deps = [
    pkgs.pacman
    pkgs.python38Full
    pkgs.replitPackages.stderred
    pkgs.libuuid.lib
  ];
  env = {
    PYTHONBIN = "${pkgs.python38Full}/bin/python3.8";
    LANG = "en_US.UTF-8";
  };
}

That doesn’t appear to reflect the change I suggested

I just saw the error in my previous response. I will fix the command, then please run the new one.
Fixed:

Thank you for your help.
but No, It also not worked, same error showing.

Could you please send the current contents of your replit.nix file?