如何在Jupyter Notebook中解决“没有名为'hmmlearn'的模块”错误

4

我是hmmlearn的新手,并尝试使用Jupyter Notebook来完成这个股票数据高斯HMM示例。然而,当我运行以下代码时,出现了错误。

from __future__ import print_function

import datetime

import numpy as np
from matplotlib import cm, pyplot as plt
from matplotlib.dates import YearLocator, MonthLocator
try:
    from matplotlib.finance import quotes_historical_yahoo_ochl
except ImportError:
    # For Matplotlib prior to 1.5.
    from matplotlib.finance import (
        quotes_historical_yahoo as quotes_historical_yahoo_ochl
    )

from hmmlearn.hmm import GaussianHMM


print(__doc__)

错误信息如下:
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-02bbde14d4d4> in <module>()
     14     )
     15 
---> 16 from hmmlearn.hmm import GaussianHMM
     17 
     18 

ModuleNotFoundError: No module named 'hmmlearn'

我花了一些时间在互联网上搜索并尝试找出为什么会发生这种情况。我确保已下载了依赖项(scikit-learn、numpy和scipy),并且我已经通过Windows cmd和如此提到的这里运行了pip install -U --user hmmlearn。但是,我一直收到相同的错误。我不确定这是否与我的计算机上不同软件包的位置有关(我正在使用Windows)。 有人有建议可以尝试解决这个问题吗? (我的主要目标只是能够设置hmmlearn,以便我可以开始使用它来探索HMMs。)

你的电脑里有多个Python吗?你能在Shell中导入hmmlearn吗? - joaquin
1
请在两个shell中检查导入,py2和py3。 - joaquin
当我在Python 2的shell中运行import hmmlearn时,它似乎是正常运行的。没有返回任何内容,提示符也像往常一样显示出来。当我在Python 3的shell中运行import hmmlearn时,我得到了与我在问题中发布的相同的错误。有什么建议吗? - Caleb Owusu-Yianoma
如果您的代码在py3上运行,则说明存在问题。您应该在py3上安装hmmlearn,可以使用pip3而不是pip。 - joaquin
@CKKOY,你解决问题了吗? - toing_toing
显示剩余2条评论
2个回答

2
这个网页提供了许多科学开源扩展包的32位和64位Windows二进制文件,适用于Python编程语言的官方CPython发行版。根据您的系统要求选择适当的文件。(对我来说,是python 3.7和windows 64位)下载完成后,在与.whl文件相同的文件夹中打开命令提示符并键入:
pip install hmmlearn-0.2.1-cp37-cp37m-win_amd64.whl

那么你可以像这样在 Jupyter Notebook 中使用 hmmlearn:

import hmmlearn
# Or 
from hmmlearn import hmm

1

我尝试在笔记本单元格中直接运行“pip install hmmlearn”。之后,我重新启动了内核,然后它就可以正常工作了。请尝试看看是否适用于您。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接