SciKit-Learn error in console

Problem description:
I have a small Python program using the Scikit-Learn library. When I run the program using the console, it returns an error, but when I run it in the shell (i.e. python main.py) it is working without any error.

Expected behavior:
Program running without problems in the console.

Actual behavior:
This error appears:

Traceback (most recent call last):
  File "/home/runner/Praktikum-03-rahmadsiswa/venv/lib/python3.8/site-packages/numpy/core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/home/runner/Praktikum-03-rahmadsiswa/venv/lib/python3.8/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/home/runner/Praktikum-03-rahmadsiswa/venv/lib/python3.8/site-packages/numpy/core/overrides.py", line 6, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libz.so.1: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    import numpy as np
  File "/home/runner/Praktikum-03-rahmadsiswa/venv/lib/python3.8/site-packages/numpy/__init__.py", line 141, in <module>
    from . import core
  File "/home/runner/Praktikum-03-rahmadsiswa/venv/lib/python3.8/site-packages/numpy/core/__init__.py", line 49, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "/home/runner/Praktikum-03-rahmadsiswa/venv/bin/python"
  * The NumPy version is: "1.24.3"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libz.so.1: cannot open shared object file: No such file or directory

Steps to reproduce:

Bug appears at this link:

Browser/OS/Device:

1 Like

It looks like your Python program is encountering an error related to a missing library file called “libz.so.1”, which is needed for the NumPy library to function. This file is typically part of the zlib library used for data compression.

Since your program runs without issue when executed in the shell but not in the console, it’s possible that there may be some environmental or path-related issues when running the program from the console.

To resolve this issue, you can first check if the zlib library is installed on your system. If it’s not, you can install it using your operating system’s package manager. For example, on Ubuntu, you can install the zlib library by running the command “sudo apt-get install zlib1g-dev” in the console.

If the library is already installed, you can check the path where the libraries are located by running “ldconfig -p | grep libz.so.1” in the console. If the library is not found, you may need to add the path to the library to the LD_LIBRARY_PATH environment variable. You can do this by running “export LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH” in the console, where “/path/to/lib” is the path to the directory where the library is located.

Once you’ve set up the environment variables or paths correctly, try running your program again in the console to see if the error has been resolved. If it did not work, respond to this message.

Thank you!