简体   繁体   English

安装无法解决 ModuleNotFoundError: No module named 'mpl_finance'

[英]installing doesn't resolve ModuleNotFoundError: No module named 'mpl_finance'

The title says it all.标题说明了一切。 Upon trying to run code related to this matplotlib candlestikck tutorial , I got the error:在尝试运行与此matplotlib 烛台教程相关的代码时,我收到了错误:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-5aa61276079d> in <module>
      2 import numpy as np
      3 import yfinance
----> 4 from mpl_finance import candlestick_ohlc
      5 import matplotlib.dates as mpl_dates
      6 import matplotlib.pyplot as plt

ModuleNotFoundError: No module named 'mpl_finance'

So I installed it and restarted the kernel but still no dice.所以我安装了它并重新启动了 kernel 但仍然没有骰子。 Next, I followed someone's advice on here and installed mplfinance and restarted the kernel, again no go.接下来,我在这里按照某人的建议安装了 mplfinance 并重新启动了 kernel,再次没有 go。 I rebooted, nil.我重启了,没有。 I even tried installing "mlp_finance" as another answer on here suggested hoping it was some weird name clashing thing but again it didn't work.我什至尝试安装“mlp_finance”作为此处的另一个答案,建议希望它是一些奇怪的名称冲突的东西,但它再次不起作用。 Why cannot I import mplfinance?为什么我不能导入 mplfinance?

Addition 202007311328: this is a jupyter notebook;加法202007311328:这是一个jupyter notebook; I can install and import fine on the command line.我可以在命令行上很好地安装和导入。 Installing mpl_finance from inside jupyter with ":pip3 install mpl_finance" produces no error:使用 ":pip3 install mpl_finance" 从 jupyter 内部安装 mpl_finance 不会产生错误:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: mpl_finance in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (0.10.1)
Requirement already satisfied: matplotlib in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from mpl_finance) (3.2.1)
Requirement already satisfied: numpy>=1.11 in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from matplotlib->mpl_finance) (1.18.4)
Requirement already satisfied: cycler>=0.10 in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from matplotlib->mpl_finance) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from matplotlib->mpl_finance) (2.4.7)
Requirement already satisfied: python-dateutil>=2.1 in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from matplotlib->mpl_finance) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from matplotlib->mpl_finance) (1.2.0)
Requirement already satisfied: six in /home/pi/src/pyfin1/pyfin1.env2/lib/python3.7/site-packages (from cycler>=0.10->matplotlib->mpl_finance) (1.14.0)

but the same error happens when I try to import it.但是当我尝试导入它时会发生同样的错误。

edit 2020071343 here's an image of my tying to install mplfinance and then use it.编辑 2020071343 这是我安装 mplfinance 然后使用它的图像。 anything pop out at you?有什么突然出现在你身上吗? jupyter notebook 安装和导入 mplfinance 的序列

solved, see https://github.com/jupyter/notebook/issues/3311已解决,见https://github.com/jupyter/notebook/issues/3311

In my experience, unless the module has been misspelled (which doesn't appear to be the case based on your screenshot above), ModuleNotFoundError usually indicates that the install location is not within the search path for importing modules.根据我的经验,除非模块拼写错误(根据上面的屏幕截图,这似乎不是这种情况), ModuleNotFoundError通常表示安装位置不在导入模块的搜索路径中。

Since this is working for you under ipython, so have a simple way to find where your system installed mplfinance:因为这在 ipython 下对你有用,所以有一个简单的方法来找到你的系统安装 mplfinance 的位置:

In [1]: import mplfinance as mpf
In [2]: mpf.__file__

To find out where your system is searching for modules找出您的系统在哪里搜索模块

import sys
print(sys.path)

If you run the above for both ipython and in your jupyter notebook , I am guessing that you will find that sys.path is different for your ipython installation than it is for your jupyter notebook (and that the notebook's search path does not include the install location).如果您在ipythonjupyter notebook中运行上述内容,我猜您会发现 ipython 安装的sys.path与 jupyter notebook不同(并且笔记本的搜索路径不包括安装地点)。 This could be for various reasons such as environment variables, where jupyter is installed, whether you are running virtual and/or conda environments, etc. You can read more about the module search path here: https://docs.python.org/3/tutorial/modules.html#the-module-search-path这可能是由于各种原因,例如环境变量、安装 jupyter 的位置、您是否正在运行虚拟和/或 conda 环境等。您可以在此处阅读有关模块搜索路径的更多信息: https://docs.python.org/ 3/tutorial/modules.html#the-module-search-path

Note that if you are using a virtual environment, or conda environment, you have to (1) activate the environment before installing mplfinance and (2) activate the environment before running jupyter notebook.请注意,如果您使用的是虚拟环境或 conda 环境,则必须 (1) 在安装mplfinance之前激活环境,以及 (2) 在运行 jupyter notebook 之前激活环境。 It may also be necessary to have a separate install of jupyter notebook in the activated environment.可能还需要在激活的环境中单独安装 jupyter notebook。

Let me know if the above gives you enough information to resolve the issue.让我知道以上是否为您提供了足够的信息来解决问题。 If not, please provide the output from the above commands and I will do what I can to help further.如果没有,请从上述命令中提供 output,我会尽我所能提供进一步的帮助。 All the best.一切顺利。 --Daniel ——丹尼尔

This had happened to me once.这曾经发生在我身上。 In my case the problem was:就我而言,问题是:

Usually pc had 2 versions of python installed - Python 2, Python3.通常 pc 安装了 2 个版本的 python - Python 2,Python3。 If you run pip install.. .如果您运行 pip 安装... It just install that module to python2 or Python3 by own.它只是自行将该模块安装到 python2 或 Python3。

Solution: If your program runs under python3解决方法:如果你的程序在python3下运行

python3 -m pip install mpl_finance

If your program runs under python2如果你的程序在 python2 下运行

python2 -m pip install mpl_finance

Hope it solves your problem.希望它能解决你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM