Pandas导入错误 " ImportError: cannot import name 'DtypeArg' from 'pandas.

您所在的位置:网站首页 pandas怎么导入 Pandas导入错误 " ImportError: cannot import name 'DtypeArg' from 'pandas.

Pandas导入错误 " ImportError: cannot import name 'DtypeArg' from 'pandas.

2023-04-14 13:04| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

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 import pandas as pd File "C:\Anaconda\envs\ED\lib\site-packages\pandas\__init__.py", line 144, in from pandas.io.api import ( File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\api.py", line 8, in 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 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 from pandas.io.parsers import TextParser File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\parsers\__init__.py", line 1, in from pandas.io.parsers.readers import ( File "C:\Anaconda\envs\ED\lib\site-packages\pandas\io\parsers\readers.py", line 17, in from pandas._typing import ( ImportError: cannot import name 'DtypeArg' from 'pandas._typing' (C:\Anaconda\envs\ED\lib\site-packages\pandas\_typing.py)

error

推荐答案

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.

其他推荐答案

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.


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3