如何解决python执行代码时出现numpy错误

问题描述 投票:0回答:1
import numpy as np
import pandas as pd

url = "https://web.archive.org/web/20230902185326/https://en.wikipedia.org/wiki/List_of_countries_by_GDP_%28nominal%29"
tables = pd.read_html(url)
df = tables[3]
print(df)

我已经在 vscode 中执行了此代码,并且 pandas 和 numpy 都已安装,即使代码无法正常工作,我收到以下错误

File "c:\Users\ASUS\Desktop\Python\lab.py", line 2, in <module>
    import pandas as pd
  File "C:\Users\ASUS\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\__init__.py", line 39, in <module>
    from pandas.compat import (
  File "C:\Users\ASUS\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\compat\__init__.py", line 26, in <module>
    from pandas.compat.numpy import is_numpy_dev
  File "C:\Users\ASUS\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\compat\numpy\__init__.py", line 9, in <module>
    _np_version = np.__version__
                  ^^^^^^^^^^^^^^
AttributeError: module 'numpy' has no attribute '__version__'

我尝试卸载并安装 pandas 和 numpy 但没有用它仍然给出相同的错误

python pandas numpy error-handling pip
1个回答
0
投票

尝试卸载并重新安装 numpy:

pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy

基于https://github.com/ipython/ipyparallel/issues/349#issuecomment-449402168

© www.soinside.com 2019 - 2024. All rights reserved.