即使我正确安装,导入 numpy 也出错

问题描述

我正在使用一个名为investpy 的模块,而numpy 是它的一个依赖项。我尝试运行 pip installinvestpy,它安装了所有依赖项(或者它说的)。但是,当我尝试运行时

import numpy

import investpy

,我遇到了这个错误

    Traceback (most recent call last):
  File "C:\Users\kakor\OneDrive\Desktop\ML\numpy\__init__.py",line 124,in <module>
    from numpy.__config__ import show as show_config
ModuleNotFoundError: No module named 'numpy.__config__'

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kakor\OneDrive\Desktop\ML\stockscreener.py",line 1,in <module>
    import numpy
  File "C:\Users\kakor\OneDrive\Desktop\ML\numpy\__init__.py",line 129,in <module>
    raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree,and relaunch
        your python interpreter from there.

我真的很困惑为什么会发生这种情况,因为据我所知,我正确安装了 numpy。此外,这真的很奇怪,因为如果我在 cmd 中转到 python 目录并运行 import numpy,它会完美运行。

任何帮助将不胜感激。谢谢!

解决方法

本质上 numpy 似乎抱怨它不是从标准路径导入的。 看起来您将 numpy 直接安装到 C:\Users\kakor\OneDrive\Desktop\ML\numpy 下的项目目录中,您应该删除该目录并尝试运行

pip install numpy