How to solve import error for pandas?

2020-01-25 09:26发布

I installed Anaconda with python 2.7.7.
However, whenever I run "import pandas" I get the error:
"ImportError: C extension: y not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first."
I tried running the suggested command but it stated that

skipping 'pandas\index.c' Cython extension (up-to-date)      
skipping 'pandas\src\period.c' Cython extension (up-to-date) 
skipping 'pandas\algos.c' Cython extension (up-to-date)      
skipping 'pandas\lib.c' Cython extension (up-to-date)        
skipping 'pandas\tslib.c' Cython extension (up-to-date)      
skipping 'pandas\parser.c' Cython extension (up-to-date)     
skipping 'pandas\hashtable.c' Cython extension (up-to-date)  
skipping 'pandas\src\sparse.c' Cython extension (up-to-date) 
skipping 'pandas\src\testing.c' Cython extension (up-to-date)
skipping 'pandas\msgpack.cpp' Cython extension (up-to-date)

Has anyone encountered this before and found a solution?

11条回答
Rolldiameter
2楼-- · 2020-01-25 10:08

I just had exactly the same issue when running tox.

Steps to solve:

  1. Update setup.py to contain pandas==0.23.0 (instead of 0.21.0).
  2. Remove .tox directory
  3. Run tox again.
查看更多
Deceive 欺骗
3楼-- · 2020-01-25 10:09

Pandas has portions of its code written in C to make it run faster. If you tried to install pandas manually you would need to build it. Try reinstalling it with miniconda package manager here: http://conda.pydata.org/miniconda.html

and then you can just do

conda install pandas

There are very simple instructions on how to do it in the link below. Just do ctrl-f miniconda to find the section that talks about it

http://pandas.pydata.org/pandas-docs/dev/install.html

查看更多
贪生不怕死
4楼-- · 2020-01-25 10:10

Actually, none of these answers worked for me in the following environment:

docker-compose # multiple containers, the managing one based on debian
Python 2.7
Django 1.8.19
numpy==1.11.3 # pinned to version, because of https://github.com/rbgirshick/py-faster-rcnn/issues/481

... more requirements

The following solution worked, after reading

https://github.com/pandas-dev/pandas/issues/18281

and

https://github.com/pandas-dev/pandas/issues/16715

which both addressed interim solutions and later recommended upgrading,

so I integrated into the Dockerfile

pip install -r requirements.txt \
&& pip install \
pandas==0.21.0 \
--force-reinstall \
--upgrade \
--no-deps \
--no-cache \
--find-links https://3f23b170c54c2533c070-1c8a9b3114517dc5fe17b7c3f8c63a43.ssl.cf2.rackcdn.com/ \
--no-index

which is mentioned in https://github.com/pandas-dev/pandas/issues/16715#issuecomment-310063504

I tried all solutions mentioned here, except the accepted answer, also because a) I don't want anaconda in a web production environment and b) it's not a good answer to foster frameworks or cli-solutions for architectures, where a package is not used standalone...

Furthermore, I dislike @colo's answer being downvoted, because it actually is a feasible solution in a certain environment.

For anyone finding this thread with similar requirements and expectations like me, I hope to have saved some minutes.

查看更多
叛逆
5楼-- · 2020-01-25 10:12

I was unable to upgrade pandas with regular

pip install --upgrade pandas 

"tensorflow 1.6.0 has requirement numpy>=1.13.3, but you'll have numpy 1.13.1 which is incompatible."

However bumping it with:

pip install --upgrade pandas --force

solved issue completely

查看更多
女痞
6楼-- · 2020-01-25 10:14

I was having this problem with python 2.7.13 here is my solution: 1. install Cython with

pip install Cython

2. install g++ and gcc

apt-get install gcc, g++

3. uninstall pandas

pip uninstall pandas

4. reinstall pandas

pip install pandas

then everything will be OK.

查看更多
登录 后发表回答