18

I am not able to import pandas

 C:\Users\Yash\Desktop\Python\Twitter Sentimental Analysis>python import.py
Traceback (most recent call last):
  File "C:\Users\Yash\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\__init__.py", line 26, in <module>
    from pandas._libs import (hashtable as _hashtable,
  File "C:\Users\Yash\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\_libs\__init__.py", line 4, in <module>
    from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
ModuleNotFoundError: No module named 'pandas._libs.tslib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "import.py", line 4, in <module>
    import pandas as pd
  File "C:\Users\Yash\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\__init__.py", line 35, in <module>
    "the C extensions first.".format(module))
ImportError: C extension: No module named 'pandas._libs.tslib' 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.

I tried screwing around but this error stayed the same. I have updated the modules already along with pip and python!

This is the full traceback of the command.

I am currently using python 3.6.6 (downloaded from the official site)

pip version : 18.1 running on windows 10 laptop!!

Yash Soni
  • 294
  • 2
  • 4
  • 12

3 Answers3

25

I faced a similar issue and solved it by manually uninstalling pandas and then installing pandas using pip. You have mentioned that you have only updated pandas. So I assume you haven't tried re-installing it.

While doing so pandas version in my environment changed from 0.23.4 to 0.24.1

My Environment :

python 3.6.7

pip 18.1

Note : I am also a beginner in Python usage. More experienced users may know a better way.

pip uninstall pandas
pip install pandas 

The above steps solved my issues and I am able to import pandas.

I checked the release notes in pandas community and it seems like the dependency on tslib has been removed. Check section 1.5 in the below link and search for tslib.

http://pandas.pydata.org/pandas-docs/version/0.24/pandas.pdf

nitin3685
  • 825
  • 1
  • 9
  • 20
  • 1
    Good suggestion on doing a fresh install. I didn't uninstall and reinstall, but rather created a conda environment with all the latest python, pandas, numpy, scipy, etc. And this also solved the problem. – Jethro Cao Dec 24 '19 at 19:17
  • 1
    What if I don't have pip. And don't want to have it. My app works from command line but fails with this exception when started from PyCharm – Emiter Apr 29 '20 at 09:09
4

I faced the same error and resolved it by calling the following commands:

pip uninstall pandas  
pip install pandas
pip3 install --upgrade pandas
Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
mustafa can nacak
  • 147
  • 1
  • 1
  • 5
0

I was facing the same error. I tried the above solutions didn't work out. Here what worked for me.

If you have two different python env and trying to run files from different env then first you have to uninstall pandas from both env and install them in the new env.

For example, I have installed python3.6 and python3.9, so first I uninstalled pandas from 3.6

sudo pip3.6 uninstall pandas

I repeated this command serval times until all versions of pandas have uninstalled. after that, I install the pandas in 3.9 using this command

/usr/bin/python3.9 -m pip install pandas
Aaditya Ura
  • 12,007
  • 7
  • 50
  • 88