Open
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
# in an environment where numpy fails to be imported because for example libstdc++.so.6 doesn't exist
import pandas
Issue Description
I was importing pandas in an environment where libstdc++.so.6
could not be found, which causes numpy to fail to load its C++ extensions.
The error I got was the following:
Traceback (most recent call last):
File "/home/nora/projects/rplcs-events-tournament-1/report_generator.py", line 2, in <module>
import pandas as pd
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/pandas/__init__.py", line 19, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
This does not contain any information about the missing shared library. If I patch out this custom throw
Line 13 in 57fd502
raise _e
I get the full error, which mentioned missing libstdc++.so.6
which was very useful to debug the issue (hidden in a details tag as it's big):
The full error
Traceback (most recent call last):
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/numpy/_core/__init__.py", line 23, in <module>
from . import multiarray
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/numpy/_core/multiarray.py", line 10, in <module>
from . import overrides
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/numpy/_core/overrides.py", line 7, in <module>
from numpy._core._multiarray_umath import (
ImportError: libstdc++.so.6: 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 "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/numpy/__init__.py", line 114, in <module>
from numpy.__config__ import show_config
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/numpy/__config__.py", line 4, in <module>
from numpy._core._multiarray_umath import (
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/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.12 from "/home/nora/projects/rplcs-events-tournament-1/.venv/bin/python3"
* The NumPy version is: "2.2.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: libstdc++.so.6: cannot open shared object file: No such file or directory
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/nora/projects/rplcs-events-tournament-1/report_generator.py", line 2, in <module>
import pandas as pd
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/pandas/__init__.py", line 16, in <module>
raise _e
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/pandas/__init__.py", line 14, in <module>
__import__(_dependency)
File "/home/nora/projects/rplcs-events-tournament-1/.venv/lib/python3.12/site-packages/numpy/__init__.py", line 119, in <module>
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
Expected Behavior
Pandas printing the full error, including nested exceptions.
Installed Versions
It can't run it because my environment is broken, but I can see the relevant code on master. Pandas version is 2.2.3