installing doesn't resolve ModuleNotFoundError: No module named 'mpl_finance'

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 19:47:56

问题


The title says it all. Upon trying to run code related to this 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


回答1:


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




回答2:


This had happened to me once. In my case the problem was:

Usually pc had 2 versions of python installed - Python 2, Python3. If you run pip install.. . It just install that module to python2 or Python3 by own.

Solution : If your program runs under python3

python3 -m pip install mlp_finance

If your program runs under python2

python2 -m pip install mlp_finance

Hope it solves your problem.



来源:https://stackoverflow.com/questions/63189797/installing-doesnt-resolve-modulenotfounderror-no-module-named-mpl-finance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!