pandas: BUG: can't import pandas

  • 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>

About this issue

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

Most upvoted comments

Try below options

option1

pip uninstall pandas pip install pandas --upgrade

option2

pip install pandas==1.1.5

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)

Usage of --ignore-installed could cause this (https://github.com/pypa/pip/issues/5020), don’t directly find the actual docker files for the image to see if that’s the case.