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条回答
走好不送
2楼-- · 2020-01-25 09:57

I was having the same problem now with Python 3.4.3.

I was using pandas-0.18.0.

Upgrading (using pip) solved the issue for me:

[sudo] pip install --upgrade pandas

The final result of the upgrade:

Successfully installed numpy-1.13.3 pandas-0.21.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0

After this, the issue was gone!

查看更多
一夜七次
3楼-- · 2020-01-25 09:57

try

/miniconda3/bin/conda install python

python: 3.6.0-0 --> 3.6.1-2

and

/miniconda3/bin/conda install pandas

Try the same with your Anaconda version.

查看更多
时光不老,我们不散
4楼-- · 2020-01-25 09:58

I had the same problem and the issue came from an encoding problem. My os was previously set up in French and everything was fine. But then when I switched to English I had the error above.

You can type

locale

in the terminal to check the local environment variables.

When set up in French, I had this configuration: French config. Then, after I switched to English, I had: English config.

I then added the following lines in the .bash_profile under /Users/myName and everything went back to normal.

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
查看更多
▲ chillily
5楼-- · 2020-01-25 09:58

Instead of installing it with conda or pip, try to install it with your package manager:

sudo apt-get install python3-pandas

查看更多
祖国的老花朵
6楼-- · 2020-01-25 10:00

I had this issue when I needed up upgrade from Python 32 bit to 64 bit to use tensorflow.

Running this command uninstalled pandas 0.21 and reinstalled 0.22 :

pip install --upgrade pandas

Sorted.

查看更多
相关推荐>>
7楼-- · 2020-01-25 10:03

I tried all the solutions above, but nothing works out...

Error Message

I got an error message with ipython

ImportError: C extension: iNaT 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.

and it suggests

$ python setup.py build_ext --inplace --force

Solution

My suggestion: Be careful about the version issue!

I clone pandas from the official github repo, then build it myself and install by pip

Following is the command I typed in terminal

$ cd pandas

$ python setup.py build_ext --inplace --force

$ sudo pip install .  # don't forget the dot 

or, if you want to install in your personal Linux account instead of under the system (due to multiple users issue)

you can add --user flag

$ pip --user install . # don't forget the dot, too

Now, everything works fine on my laptop

My configuration

Ubuntu 16.04
Python 2.7
Numpy 1.13.1 

Good luck!

查看更多
登录 后发表回答