1

I am getting this on a Raspberry Pi zero after having used it no problem for months, I just turned it on again after a few months and now I can't import pandas:

Python 3.7.3 (default, Oct 31 2022, 14:04:00) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pandas as pd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py", line 22, in <module>
    from pandas.compat import (
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/compat/__init__.py", line 15, in <module>
    from pandas.compat.numpy import (
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
    from pandas.util.version import Version
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/util/__init__.py", line 1, in <module>
    from pandas.util._decorators import (  # noqa
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/util/_decorators.py", line 14, in <module>
    from pandas._libs.properties import cache_readonly  # noqa
  File "/home/pi/.local/lib/python3.7/site-packages/pandas/_libs/__init__.py", line 13, in <module>
    from pandas._libs.interval import Interval
  File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject

This error is very similar to the one in this question, but slightly different.

I tried updating my system:

sudo apt update

And I tried uninstalling and re-installing numpy and pandas:

sudo apt remove python3-numpy python3-pandas
sudo apt-get install python3-numpy python3-pandas python3-scipy python3-sklearn python3-numexpr

but it does not fix it.

Any ideas?

Version info

python3-numpy/oldstable,now 1:1.16.2-1 armhf [installed]
python3-pandas-lib/oldstable,now 0.23.3+dfsg-3 armhf [installed,automatic]
python3-pandas/oldstable,now 0.23.3+dfsg-3 all [installed]

System info

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
Bill
  • 10,323
  • 10
  • 62
  • 85
  • Is there a reason you're not using pip or conda? – jared Jun 25 '23 at 04:27
  • The Raspberry Pi doesn't have enough memory to build numpy. They need to use an apt binary. – Tim Roberts Jun 25 '23 at 04:30
  • @jared I've tried miniconda on the RPi and pip and found apt-get worked best (everything was working fine when I last turned it on). This is also recommended by [Geoff Boing](http://geoffboeing.com/2016/03/scientific-python-raspberry-pi/) – Bill Jun 25 '23 at 04:36
  • 1
    @Bill I recommend adding the library versions to your post. It may be relevant. – jared Jun 25 '23 at 04:38
  • @jared I added the pandas and numpy versions. I can show others if needed. – Bill Jun 25 '23 at 04:45
  • @TimRoberts Numpy is working fine. It's just Pandas. – Bill Jun 25 '23 at 04:47
  • 2
    From your error, imported pandas is in `/home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py` - the apt-get one should be in `/usr/` somewhere. This looks like a `pip --user` install. – Rory Yorke Jun 25 '23 at 05:14
  • Hi @RoryYorke. You might be right. `pip list` shows `pandas 1.3.5`. What do you think? Should I uninstall that or the apt-get one? – Bill Jun 25 '23 at 05:25

1 Answers1

2

Thanks @Rory Yorke for figuring out the problem in the comments.

From your error, imported pandas is in /home/pi/.local/lib/python3.7/site-packages/pandas/__init__.py - the apt-get one should be in /usr/ somewhere. This looks like a pip --user install.

Clearly there were two version of Pandas installed. Removing the pip version solved the problem:

pi@raspberrypi:~/code $ pip uninstall pandas
Found existing installation: pandas 1.3.5
Uninstalling pandas-1.3.5:
  Would remove:
    /home/pi/.local/lib/python3.7/site-packages/pandas-1.3.5.dist-info/*
    /home/pi/.local/lib/python3.7/site-packages/pandas/*
Proceed (Y/n)? Y
  Successfully uninstalled pandas-1.3.5
pi@raspberrypi:~/code $ python
Python 3.7.3 (default, Oct 31 2022, 14:04:00) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pandas as pd
>>> 
jared
  • 4,165
  • 1
  • 8
  • 31
Bill
  • 10,323
  • 10
  • 62
  • 85