question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: can't import pandas

See original GitHub issue
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd

Problem description

[I am just trying to import pandas to run my notebook and it is throwing this error

ImportErrorTraceback (most recent call last)
<ipython-input-1-f20def6a2be1> in <module>
      1 import numpy as np
----> 2 import pandas as pd

~/anaconda3/lib/python3.8/site-packages/pandas/__init__.py in <module>
    142 from pandas.util._print_versions import show_versions
    143 
--> 144 from pandas.io.api import (
    145     # excel
    146     ExcelFile,

~/anaconda3/lib/python3.8/site-packages/pandas/io/api.py in <module>
      6 
      7 from pandas.io.clipboards import read_clipboard
----> 8 from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
      9 from pandas.io.feather_format import read_feather
     10 from pandas.io.gbq import read_gbq

~/anaconda3/lib/python3.8/site-packages/pandas/io/excel/__init__.py in <module>
----> 1 from pandas.io.excel._base import ExcelFile, ExcelWriter, read_excel
      2 from pandas.io.excel._odswriter import ODSWriter as _ODSWriter
      3 from pandas.io.excel._openpyxl import OpenpyxlWriter as _OpenpyxlWriter
      4 from pandas.io.excel._util import register_writer
      5 from pandas.io.excel._xlsxwriter import XlsxWriter as _XlsxWriter

~/anaconda3/lib/python3.8/site-packages/pandas/io/excel/_base.py in <module>
     31     pop_header_name,
     32 )
---> 33 from pandas.io.parsers import TextParser
     34 
     35 _read_excel_doc = (

~/anaconda3/lib/python3.8/site-packages/pandas/io/parsers/__init__.py in <module>
----> 1 from pandas.io.parsers.readers import (
      2     TextFileReader,
      3     TextParser,
      4     read_csv,
      5     read_fwf,

~/anaconda3/lib/python3.8/site-packages/pandas/io/parsers/readers.py in <module>
     15 import pandas._libs.lib as lib
     16 from pandas._libs.parsers import STR_NA_VALUES
---> 17 from pandas._typing import (
     18     ArrayLike,
     19     DtypeArg,

ImportError: cannot import name 'DtypeArg' from 'pandas._typing' (/home/tope/anaconda3/lib/python3.8/site-packages/pandas/_typing.py)```]

#### Expected Output

#### Output of ``pd.show_versions()``

<details>

[paste the output of ``--------------------------------------
NameErrorTraceback (most recent call last)
<ipython-input-4-3d232a07e144> in <module>
----> 1 pd.show_versions()

NameError: name 'pd' is not defined`` here leaving a blank line after the details tag]

</details>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:27 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
sangilkicommented, Jul 12, 2021

Try below options

option1

pip uninstall pandas pip install pandas --upgrade

option2

pip install pandas==1.1.5

1reaction
jorisvandenbosschecommented, Aug 12, 2021

The sequence was the other way round: first newer pandas with pip, then older with conda

Ah, yes, I was confused by the timestamp of the different (old and new) files in the pandas directory in site-packages, but I suppose those don’t necessarily reflect installation time.

It seems this is a known issue with conda/pip compatibility (and the specific example here is easily reproduced locally: create new conda env, install pandas with pip, install pandas=1.2.5 with conda, and you get the error). See for example https://www.anaconda.com/blog/using-pip-in-a-conda-environment where one of the recommendations is “don’t use conda after pip” (first install everything you can with conda, and then the rest with pip). The back and forth conda / pip / conda / … usage is likely to give problems.

You can blame cudf for pinning pandas, but I suppose it should also be quite straightforward to not install pandas with pip before you install cudf with conda. If performance of conda is a concern, I recommend to check out mamba (a fast almost drop-in replacement, https://github.com/mamba-org/mamba)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ImportError: No module named pandas [Mac/Linux ...
Quick Fix: Python raises the ImportError: No module named pandas when it cannot find the Pandas installation. The most frequent source of this...
Read more >
python - Can't Import Pandas - Stack Overflow
It would seem that Conda does not have all of your packages, I'd suggest using Anaconda and follow those instructions it has all...
Read more >
No Module Named Pandas – How To Fix - Data Independent
“no module named pandas” happens because because your current python environment cannot find the pandas library. Here's a list of the common reasons...
Read more >
How to Fix: No module named pandas - GeeksforGeeks
The error “No module named pandas ” will occur when there is no pandas library in your environment IE the pandas module is...
Read more >
No module named 'pandas' when import pandas - Microsoft Q&A
You may have different Python versions on your computer and Pandas is not installed for the particular version you're using. You can run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found