【问题标题】:Jupyter gets Import Error when importing matplotlibJupyter 在导入 matplotlib 时出现导入错误
【发布时间】:2016-03-31 20:46:09
【问题描述】:

我刚刚尝试集成到 Jupyter,并且我已经使用 Anaconda 很长时间了。

尝试在 IPython Notebook 中导入 matplotlib 时,

import matplotlib.pyplot as plt
%matplotlib inline

我收到此错误:

ImportError                               Traceback (most recent call last)
<ipython-input-2-385145dcc870> in <module>()
----> 1 import matplotlib.pyplot as plt
      2 get_ipython().magic(u'matplotlib inline')

ImportError: No module named matplotlib.pyplot

【问题讨论】:

  • rm -rf ~/Library/Enthought/
  • 因为移除 Canopy Application 不会移除主目录中的文件夹。 support.enthought.com/entries/…
  • 我当时删除了它。现在再次尝试 matplotlib 时,我得到了这个——在编辑中。

标签: python matplotlib ipython jupyter enthought


【解决方案1】:

我遇到了同样的问题。然后我使用以下命令将 matplotlib 库安装到我的虚拟环境中。

pip install matplotlib

然后我可以将 matplotlib 导入到 jupyter notebook。

【讨论】:

    【解决方案2】:

    如果使用 conda 然后在终端类型中,我认为您应该安装 matplotlib 库:

    # create a new environment with the required packages
    conda create -n "matplotlib_build" python=3.5 numpy python-dateutil pyparsing pytz tornado cycler tk libpng zlib freetype
    activate matplotlib_build
    # if you want a qt backend, you also have to install pyqt (be aware that pyqt doesn't mix well if
    # you have created the environment with conda-forge already activated...)
    conda install pyqt
    # this package is only available in the conda-forge channel
    conda install -c conda-forge msinttypes
    
    # copy the libs which have "wrong" names
    set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
    mkdir lib || cmd /c "exit /b 0"
    copy %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
    copy %LIBRARY_LIB%\libpng_static.lib lib\png.lib
    
    # Make the header files and the rest of the static libs available during the build
    # CONDA_DEFAULT_ENV is a env variable which is set to the currently active environment path
    set MPLBASEDIRLIST=%CONDA_PREFIX%\Library\;.
    
    # build the wheel
    python setup.py bdist_wheel
    

    此代码取自 https://matplotlib.org/users/installing.html#conda-packages。希望这会有所帮助。

    谢谢

    迈克尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 2023-01-04
      • 2021-12-10
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多