【问题标题】:Cannot import matplotlib with ipython/jupyter notebook无法使用 ipython/jupyter 笔记本导入 matplotlib
【发布时间】:2017-02-03 18:09:43
【问题描述】:

无法通过虚拟环境使用 ipython/jupyter notebook 导入 matplotlib。

我可以使用控制台很好地导入 matplotlib。看过其他 SO 帖子后,我似乎无法正确设置。

我关注this 获得了单独的 ipython/jupyter 内核。

当我通过 jupyter 检查我的位置时,我得到了

six.__file__:'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc'

datutil.__file__:'/Library/Python/2.7/site-packages/dateutil/__init__.pyc'

我不确定这些是否正确。以下主要 jupyter 错误

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

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py in <module>()
     27 from matplotlib import docstring
     28 from matplotlib.backend_bases import FigureCanvasBase
---> 29 from matplotlib.figure import Figure, figaspect
     30 from matplotlib.gridspec import GridSpec
     31 from matplotlib.image import imread as _imread

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py in <module>()
     34 import matplotlib.colorbar as cbar
     35 
---> 36 from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
     37 from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
     38 from matplotlib.legend import Legend

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py in <module>()
     18 import matplotlib.colors as mcolors
     19 import matplotlib.contour as mcontour
---> 20 import matplotlib.dates as _  # <-registers a date unit converter
     21 from matplotlib import docstring
     22 import matplotlib.font_manager as font_manager

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/dates.py in <module>()
    117 
    118 
--> 119 from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
    120                             MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
    121                             SECONDLY)

/Library/Python/2.7/site-packages/dateutil/rrule.py in <module>()
     17 
     18 from six import advance_iterator, integer_types
---> 19 from six.moves import _thread
     20 import heapq
     21 

ImportError: cannot import name _thread

【问题讨论】:

    标签: python python-2.7 matplotlib virtualenv jupyter


    【解决方案1】:

    好的,我通过正确使用教程解决了这个问题 (http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs)

    您需要设置一个 virtualenv,然后确保在其中安装 jupyter。我使用的是全局安装的 jupyter。

    然后设置新的 jupyter 内核(上面链接),一切都应该与正确指向的 virtualenv 一起工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 2017-10-25
      • 1970-01-01
      • 2018-11-08
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多