pandas: importing pandas breaks after successfully installing pandas with pip
Code Sample, a copy-pastable example if possible
> docker run --tty --interactive --rm python:2.7.12-alpine ash
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.6-150-gf952adf [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.6-83-g67e50bc [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5983 distinct packages available
/ # apk add cython g++ musl-dev
(1/21) Upgrading musl (1.1.14-r12 -> 1.1.14-r14)
(2/21) Installing libffi (3.2.1-r2)
(3/21) Installing python (2.7.12-r0)
(4/21) Installing cython (0.24-r1)
(5/21) Installing libgcc (5.3.0-r0)
(6/21) Installing libstdc++ (5.3.0-r0)
(7/21) Installing binutils-libs (2.26-r1)
(8/21) Installing binutils (2.26-r1)
(9/21) Installing gmp (6.1.0-r0)
(10/21) Installing isl (0.14.1-r0)
(11/21) Installing libgomp (5.3.0-r0)
(12/21) Installing libatomic (5.3.0-r0)
(13/21) Installing pkgconf (0.9.12-r0)
(14/21) Installing pkgconfig (0.25-r1)
(15/21) Installing mpfr3 (3.1.2-r0)
(16/21) Installing mpc1 (1.0.3-r0)
(17/21) Installing gcc (5.3.0-r0)
(18/21) Installing musl-dev (1.1.14-r14)
(19/21) Installing libc-dev (0.7-r0)
(20/21) Installing g++ (5.3.0-r0)
(21/21) Upgrading musl-utils (1.1.14-r12 -> 1.1.14-r14)
Executing busybox-1.24.2-r11.trigger
OK: 230 MiB in 51 packages
/ # ln -s locale.h /usr/include/xlocale.h
/ # pip install numpy==1.11.3 pandas==0.20.2
Collecting numpy==1.11.3
Downloading numpy-1.11.3.zip (4.7MB)
100% |████████████████████████████████| 4.7MB 242kB/s
Collecting pandas==0.20.2
Downloading pandas-0.20.2.tar.gz (10.3MB)
100% |████████████████████████████████| 10.3MB 124kB/s
Collecting python-dateutil (from pandas==0.20.2)
Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
100% |████████████████████████████████| 194kB 994kB/s
Collecting pytz>=2011k (from pandas==0.20.2)
Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
100% |████████████████████████████████| 491kB 874kB/s
Collecting six>=1.5 (from python-dateutil->pandas==0.20.2)
Downloading six-1.10.0-py2.py3-none-any.whl
Building wheels for collected packages: numpy, pandas
Running setup.py bdist_wheel for numpy ... done
Stored in directory: /root/.cache/pip/wheels/8f/d6/97/4cc26777ee05997164e480e2e5de2c9e9c4e32dfe325ea5bd6
Running setup.py bdist_wheel for pandas ... done
Stored in directory: /root/.cache/pip/wheels/fc/fd/0a/5857e8bee7d5cc3ca22228fb7ab5efa43be57c0f9103e54098
Successfully built numpy pandas
Installing collected packages: numpy, six, python-dateutil, pytz, pandas
Successfully installed numpy-1.11.3 pandas-0.20.2 python-dateutil-2.6.0 pytz-2017.2 six-1.10.0
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/ # python -c "import pandas"
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/pandas/__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: umpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
Problem description
Installing Pandas with pip
is successful, but import pandas
breaks.
If I issue two separate pip install
commands, one for numpy
and one for pandas
, it works:
> docker run --tty --interactive --rm python:2.7.12-alpine ash
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.6-150-gf952adf [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.6-83-g67e50bc [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5983 distinct packages available
/ # apk add cython g++ musl-dev
(1/21) Upgrading musl (1.1.14-r12 -> 1.1.14-r14)
(2/21) Installing libffi (3.2.1-r2)
(3/21) Installing python (2.7.12-r0)
(4/21) Installing cython (0.24-r1)
(5/21) Installing libgcc (5.3.0-r0)
(6/21) Installing libstdc++ (5.3.0-r0)
(7/21) Installing binutils-libs (2.26-r1)
(8/21) Installing binutils (2.26-r1)
(9/21) Installing gmp (6.1.0-r0)
(10/21) Installing isl (0.14.1-r0)
(11/21) Installing libgomp (5.3.0-r0)
(12/21) Installing libatomic (5.3.0-r0)
(13/21) Installing pkgconf (0.9.12-r0)
(14/21) Installing pkgconfig (0.25-r1)
(15/21) Installing mpfr3 (3.1.2-r0)
(16/21) Installing mpc1 (1.0.3-r0)
(17/21) Installing gcc (5.3.0-r0)
(18/21) Installing musl-dev (1.1.14-r14)
(19/21) Installing libc-dev (0.7-r0)
(20/21) Installing g++ (5.3.0-r0)
(21/21) Upgrading musl-utils (1.1.14-r12 -> 1.1.14-r14)
Executing busybox-1.24.2-r11.trigger
OK: 230 MiB in 51 packages
/ # ln -s locale.h /usr/include/xlocale.h
/ # pip install numpy==1.11.3
Collecting numpy==1.11.3
Downloading numpy-1.11.3.zip (4.7MB)
100% |████████████████████████████████| 4.7MB 221kB/s
Building wheels for collected packages: numpy
Running setup.py bdist_wheel for numpy ... done
Stored in directory: /root/.cache/pip/wheels/8f/d6/97/4cc26777ee05997164e480e2e5de2c9e9c4e32dfe325ea5bd6
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.11.3
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/ # pip install pandas==0.20.2
Collecting pandas==0.20.2
Downloading pandas-0.20.2.tar.gz (10.3MB)
100% |████████████████████████████████| 10.3MB 125kB/s
Collecting python-dateutil (from pandas==0.20.2)
Downloading python_dateutil-2.6.0-py2.py3-none-any.whl (194kB)
100% |████████████████████████████████| 194kB 787kB/s
Collecting pytz>=2011k (from pandas==0.20.2)
Downloading pytz-2017.2-py2.py3-none-any.whl (484kB)
100% |████████████████████████████████| 491kB 1.0MB/s
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in /usr/local/lib/python2.7/site-packages (from pandas==0.20.2)
Collecting six>=1.5 (from python-dateutil->pandas==0.20.2)
Downloading six-1.10.0-py2.py3-none-any.whl
Building wheels for collected packages: pandas
Running setup.py bdist_wheel for pandas ... done
Stored in directory: /root/.cache/pip/wheels/fc/fd/0a/5857e8bee7d5cc3ca22228fb7ab5efa43be57c0f9103e54098
Successfully built pandas
Installing collected packages: six, python-dateutil, pytz, pandas
Successfully installed pandas-0.20.2 python-dateutil-2.6.0 pytz-2017.2 six-1.10.0
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/ # python -c "import pandas"
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 46 (29 by maintainers)
@jlbooker opened an issue to track this here: https://github.com/pandas-dev/pandas/issues/18530 Hopefully we can quickly fix this
As I said above and please read the comments above, if it is the same problem you need to install them separately, so
pip install numpy=1.12.0
and thenpip install pandas=0.21.0
However, what system is it? It is maybe not compatible with
manylinux
requirements.But it is indeed the same issue as in https://github.com/pandas-dev/pandas/issues/11383. So when doing install from source, installing with
pip
breaks if you try to install numpy and pandas in one go (and if you are not installing the latest version of numpy). The reason is that pip seems to build pandas in a separate env for which it uses the latest numpy, but in the actual env an older version of numpy is installed, and hence the errors. Solution is just do it in two steps (then numpy is already installed, and when building pandas it will use that and not fetch another one). So either pip is just broken for this use case, or we do something wrong in our setup.py (but no expert in that)I’m seeing a similar (same?) issue under Fedora 25.
(Numpy was installed via
$ sudo dnf install python2-numpy
.)Running
import pandas as pd
:The advice from @abhishekg2389 to use pandas==0.20.2 worked to fix this:
Hi, I have installed manually also ( note: already same version only), by using “pip install numpy==1.12.0 pandas==0.21.0”
Though after, while doing python -c " import pandas" getting error as
“the C extensions first.”.format(module)) ImportError: C extension: numpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run ‘python setup.py build_ext --inplace --force’ to build the C extensions first.
Makes sense. The system is Alpine Linux 3.4.