安装无法解决ModuleNotFoundError:没有名为"mpl_finance"的模块 [英] installing doesn't resolve ModuleNotFoundError: No module named 'mpl_finance'

查看:51
本文介绍了安装无法解决ModuleNotFoundError:没有名为"mpl_finance"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.尝试运行与此

已解决,请参见 https://github.com/jupyter/notebook/issues/3311

解决方案

根据我的经验,除非模块拼写错误(根据上面的屏幕截图,情况似乎并非如此),ModuleNotFoundError通常表示安装位置不在用于导入模块的搜索路径内.

由于这在ipython下可以为您工作,因此有一种简单的方法来查找您的系统在mplfinance上安装的位置:

 在[1]中:将mplfinance导入为mpf在[2]中:mpf .__ file__

了解系统在哪里搜索模块

  import sys打印(sys.path)

如果你在 ipythonjupyter notebook 中运行上面的代码,我猜你会发现 sys.path 不同(并且笔记本的搜索路径不包括安装位置).这可能是出于各种原因,例如环境变量、安装 jupyter 的位置、是否运行虚拟和/或 conda 环境等.您可以在此处阅读有关模块搜索路径的更多信息:matplotlib candlestikck tutorial, I got the error:

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. Next, I followed someone's advice on here and installed mplfinance and restarted the kernel, again no 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. Why cannot I import mplfinance?

Addition 202007311328: this is a 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:

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. anything pop out at you?

solved, see 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.

Since this is working for you under ipython, so have a simple way to find where your system installed 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). 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

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. It may also be necessary to have a separate install of jupyter notebook in the activated environment.

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. All the best. --Daniel

这篇关于安装无法解决ModuleNotFoundError:没有名为"mpl_finance"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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