Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas importing error " ImportError: cannot import name 'DtypeArg' from 'pandas._typing' "

When I try to import pandas, it throws an error. I cannot import pandas. I re-install pandas but it keeps ont throwing the same error.

I tried running it in a local prompt and in a jupyter notebook. I think it may conflict with the pip version so I removed the package from pip. Currently I just have the conda version but still same error. What can I do?

 Traceback (most recent call last):
  File "havatahmin.py", line 1, in <module>
    import pandas as pd
  File "C:\Anaconda\envs\ED\lib\site-packages\pandas\__init__.py", line 144, in <module>
    from pandas.io.api import (
  File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\api.py", line 8, in <module>
    from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
  File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\excel\__init__.py", line 1, in <module>
    from pandas.io.excel._base import ExcelFile, ExcelWriter, read_excel
  File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\excel\_base.py", line 33, in <module>
    from pandas.io.parsers import TextParser
  File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\parsers\__init__.py", line 1, in <module>
    from pandas.io.parsers.readers import (
  File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\parsers\readers.py", line 17, in <module>
    from pandas._typing import (
ImportError: cannot import name 'DtypeArg' from 'pandas._typing' (C:\Anaconda\envs\ED\lib\site-packages\pandas\_typing.py)

error

like image 697
Doğukan CEBECİ Avatar asked Jul 21 '21 02:07

Doğukan CEBECİ


People also ask

Why does pip install pandas-ignore-installed fail?

pip install pandas --ignore-installed will break pandas between 1.3.0 and 1.3.1 because it does not remove old files from site-packages, thus the import error. If this is the case, you can re-install pandas without this flag.

How to fix apt-get import error numexpr?

It looks like apt-get only installed the required dependencies and not the highly recommended ones; as such you get an ImportError when trying to import numexpr and bottleneck. Installing these modules should most probably solve the problem.

Is the pandas woarkaround a reproducible bug?

I confirm, it is a reproducible bug in pandas==1.3.1. A workaround is to downgrade it to some earlier version, e.g. pip install pandas==1.3.0. The woarkaround can be tested in build 20210717 of our python (3.8) CUDA-enabled containers:


2 Answers

I confirm, it is a reproducible bug in pandas==1.3.1.

A workaround is to downgrade it to some earlier version, e.g. pip install pandas==1.3.0.

The woarkaround can be tested in build 20210717 of our python (3.8) CUDA-enabled containers:

docker run -d --rm --name ml-gpu-py38-cuda112-cust -p 8888:8888 -v /home/mir:/home/jovyan mirekphd/ml-gpu-py38-cuda112-cust:20210717 && docker logs -f ml-gpu-py38-cuda112-cust

Has it been already reported to pandas devs on Github?

Update: The issue still persists, so I've provided a reproducible example to Pandas devs in #42506.

like image 161
mirekphd Avatar answered Oct 09 '22 16:10

mirekphd


This error can occur for multiple reasons.

  • pip install pandas --ignore-installed will break pandas between 1.3.0 and 1.3.1 because it does not remove old files from site-packages, thus the import error. If this is the case, you can re-install pandas without this flag.
pip install --force-reinstall pandas
  • Mixing conda and pip may also break pandas, as discussed here. For that matter, if you use conda, try to stick with it then install missing packages with pip. More guidelines on how to use pip in a Conda environment.
like image 41
Val Berthe Avatar answered Oct 09 '22 17:10

Val Berthe