导入matplotlib时,Jupyter会导致导入错误

时间:2016-03-31 20:46:10

标签: python matplotlib ipython jupyter enthought

我刚刚尝试整合到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

2 个答案:

答案 0 :(得分:0)

我认为如果在终端类型中使用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。希望这会有所帮助。

谢谢

迈克尔

答案 1 :(得分:0)

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

imgback = cv2.cvtColor(imghsv, COLOR_HSV2BGR)

然后我可以将matplotlib导入jupyter笔记本。