ModuleNotFoundError: 没有名为“mplfinance"的模块 |即使在 pip 失速 mplfinance 之后也会出错 [英] ModuleNotFoundError: No module named 'mplfinance' | errors out even after pip stall mplfinance

查看:37
本文介绍了ModuleNotFoundError: 没有名为“mplfinance"的模块 |即使在 pip 失速 mplfinance 之后也会出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 MacBook 上的 Jupyter 笔记本上运行此程序会出现以下错误:

Running this on my Jupyter notebook on my MacBook gives the following error:

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并升级了它.我已经在我的终端上完成了以下操作:


But I have installed mplfinance and upgraded it too. I've done the following on my terminal:

~ 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 错误?

Restarted kernel, even restarted my laptop but I keep seeing this error. Would anyone here have an idea as to why I'm seeing the ModuleNotFoundError error despite having installed it?

非常感谢

推荐答案

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

This type of error is not related to mplfinance per se. The most common (but not only) cause of "module not found" issues (regardless of the package, and assuming that the module is installed) is that the package or module is installed in one place, but python's import path is looking somewhere else.

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

This can happen if the package was installed globally, but python is running in a virtual environment (or vis versa). It can also happen if, for example, if running jupyter notebook runs a different (other installed) version of python than the one in which the package was installed.

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

A few things you can do to diagnose the situation:

  1. 您是否在与 mplfinance 安装位置不同的虚拟环境中运行 jupyter notebook?(来自上面的跟踪:mplfinance in/usr/local/lib/python3.9/site-packages)
  2. 在终端提示符处:which jupyter 这将显示您从哪里运行 jupyter 这可能会让您了解 jupyter 从哪里运行 ipython 反过来又会给您一个想法 python 的位置 正在运行.mplfinance 的安装位置是一样的吗?
  3. 尝试在 jupyter 之外导入 mplfinance.例如,在终端提示符处键入:python -c "import mplfinance;print(mplfinance.__file__)".这行得通吗?
  4. 在此之前:
  1. Are you running jupyter notebook in a virtual environment that is different from where mplfinance is installed? (from your trace above: mplfinance in /usr/local/lib/python3.9/site-packages)
  2. At the terminal prompt: which jupyter <enter> This will show you from where you are running jupyter which may give you an idea from where jupyter is running ipython which in turn will give you an idea from where python is running. Is it the same place where mplfinance is installed?
  3. Try importing mplfinance outside of jupyter. For example, at the terminal prompt type: python -c "import mplfinance;print(mplfinance.__file__)". Does that work?
  4. Before anything else:
import sys
print(sys.path)
print(sys.executable)

第一个打印会告诉你 python 在哪里寻找包.第二个将告诉您 jupyter 从何处运行 python(这可能与安装 mplfinance 的 python 不同).

  • 比较 pip --versionpip3 --version如果您安装了多个版本,这也可以让您了解
  • The first print will tell you where python is looking to find packages. The second will tell you from where jupyter is running python (which may not be the same python where mplfinance was installed).

  • Compare pip --version to pip3 --version This may also give you an idea if you have more than one version installed

  • 找不到模块"的另一个但不太常见的原因是是一个错误的安装.如果是这样,这通常可以通过以下方式解决:pip uninstall 后跟 pip install --no-cache-dir

    这篇关于ModuleNotFoundError: 没有名为“mplfinance"的模块 |即使在 pip 失速 mplfinance 之后也会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆