Unable to import pandas in NixOS

I’m fairly new to Nix and NixOS.
Currently, I am running NixOS 22.11 and I’m still a bit lost as I didn’t read some of the docs yet.

Right now, I,m facing an issue to import pandas in python. Every time that I try to import it, I get the following error:

Traceback (most recent call last):
  File "/home/opiero/Gorila/scraper-ancord-bi/main.py", line 2, in <module>
    from s3_connector import utils
  File "/home/opiero/Gorila/scraper-ancord-bi/s3_connector/utils.py", line 2, in <module>
    import pandas as pd
  File "/home/opiero/Gorila/scraper-ancord-bi/.venv/lib/python3.10/site-packages/pandas/__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: 

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.10 from "/home/opiero/Gorila/scraper-ancord-bi/.venv/bin/python"
  * The NumPy version is: "1.24.2"

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

Googled it and did not find a solution for NixOs.

Can someone give me a hand, please?

Thank you!

EDIT: I have already installed numpy and zlib at configuration.nix

How did you install them?

Installing python modules via system configuration is easy to do wrong (and not suggested anyways). Libraries like zlib is generally not possible (FAQ - NixOS Wiki).

It is very likely that you want to set up a project specific shell here.

1 Like

Thank you sooooo much!

I have just used a project specific shell and it worked marvelously.
I also removed the python modules, which were being imported as regular packages from the system configuration.

I can now use pandas again.

Thanks!