0

在我的 MacBook 上的 Jupyter 笔记本上运行它会出现以下错误: 在此处输入图像描述

import mplfinance 

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-5bae819ae7bb> in <module>
----> 1 import mplfinance as mpl

ModuleNotFoundError: No module named 'mplfinance'

但我也安装了 mplfinance 并对其进行了升级。我在终端上完成了以下操作:

~ pip3 install mplfinance
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: mplfinance in /usr/local/lib/python3.9/site-packages (0.12.7a17)
Requirement already satisfied: pandas in /usr/local/lib/python3.9/site-packages (from mplfinance) (1.3.1)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.9/site-packages (from mplfinance) (3.4.3)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (1.3.1)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (2.8.2)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (8.3.1)
Requirement already satisfied: numpy>=1.16 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (1.21.1)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (0.10.0)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from cycler>=0.10->matplotlib->mplfinance) (1.16.0)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.9/site-packages (from pandas->mplfinance) (2021.1)
➜  ~ pip install mplfinance 
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: mplfinance in /usr/local/lib/python3.9/site-packages (0.12.7a17)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.9/site-packages (from mplfinance) (3.4.3)
Requirement already satisfied: pandas in /usr/local/lib/python3.9/site-packages (from mplfinance) (1.3.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (1.3.1)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (8.3.1)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (2.8.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (0.10.0)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (2.4.7)
Requirement already satisfied: numpy>=1.16 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (1.21.1)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from cycler>=0.10->matplotlib->mplfinance) (1.16.0)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.9/site-packages (from pandas->mplfinance) (2021.1)
➜  ~ pip install --upgrade mplfinance
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: mplfinance in /usr/local/lib/python3.9/site-packages (0.12.7a17)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.9/site-packages (from mplfinance) (3.4.3)
Requirement already satisfied: pandas in /usr/local/lib/python3.9/site-packages (from mplfinance) (1.3.1)
Requirement already satisfied: numpy>=1.16 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (1.21.1)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (2.8.2)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (8.3.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (1.3.1)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (0.10.0)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.9/site-packages (from matplotlib->mplfinance) (2.4.7)
Requirement already satisfied: six in /usr/local/lib/python3.9/site-packages (from cycler>=0.10->matplotlib->mplfinance) (1.16.0)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.9/site-packages (from pandas->mplfinance) (2021.1)
➜  ~ 

重新启动内核,甚至重新启动我的笔记本电脑,但我一直看到这个错误。尽管安装了 ModuleNotFoundError 错误,这里有人知道为什么我会看到它吗?

非常感谢

4

1 回答 1

0

这种类型的错误与 mplfinance 本身无关。“找不到模块”问题的最常见(但不仅)原因(不管包,并假设模块安装)是包或模块安装在一个地方,但 python 的导入路径正在寻找其他地方.

如果包是全局安装的,但 python 在虚拟环境中运行(反之亦然),则可能会发生这种情况。例如,如果 runningjupyter notebook运行的 python 版本与安装包的版本不同(其他已安装),也可能发生这种情况。

您可以做一些事情来诊断这种情况:

  1. 您是否在与安装 mplfinance 的位置不同的虚拟环境中运行 jupyter notebook?(来自您上面的跟踪mplfinance in /usr/local/lib/python3.9/site-packages:)
  2. 在终端提示符下:which jupyter <enter> 这将向您显示您正在运行的位置jupyter,这可能会让您了解 jupyter 的运行位置ipython,这反过来又会让您了解python运行的位置。安装mplfinance的地方是同一个地方吗?
  3. 尝试在 jupyter 之外导入 mplfinance。例如,在终端提示符下键入:python -c "import mplfinance;print(mplfinance.__file__)". 那样有用吗?
  4. 在其他任何事情之前:
    import sys
    print(sys.path)
    print(sys.executable)
    
    第一次打印会告诉你 python 在哪里寻找包。第二个将告诉您 jupyter 从哪里运行 python(可能与安装 mplfinance 的 python 不同)。
  5. 如果您安装了多个版本,这也可能会给您一个pip --version想法pip3 --version

“找不到模块”的另一个但不太常见的原因是安装错误。如果是这样,这通常可以通过以下方式解决pip uninstall <package>pip install --no-cache-dir <package>

于 2021-08-15T14:27:22.127 回答