简体   繁体   English

无法使用ipython / jupyter笔记本导入matplotlib

[英]Cannot import matplotlib with ipython/jupyter notebook

Cannot import matplotlib with ipython/jupyter notebook through a virtual environment. 无法通过虚拟环境使用ipython / jupyter笔记本导入matplotlib。

I'm able to import matplotlib just fine using the console. 我可以使用控制台轻松导入matplotlib。 Having seen other SO posts I can't seem to get this set up right. 看过其他SO帖子后我似乎无法正确设置。

I followed this to get the separate ipython/jupyter kernel. 我按照这个来获得单独的ipython / jupyter内核。

When I checked my locations through jupyter I get 当我通过jupyter检查我的位置时,我得到了

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

and

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

I am not sure these are correct. 我不确定这些是否正确。 Main jupyter error below 主要的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

Ok I fixed this by using the tutorial properly ( http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs ) 好的我通过正确使用教程修复了这个问题( http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs

You need to set up a virtualenv, then make sure that you install jupyter within it. 您需要设置virtualenv,然后确保在其中安装jupyter。 I was using the globally installed jupyter. 我正在使用全球安装的jupyter。

Then set up the new jupyter kernel (linked above) and everything should work with your virtualenv pointed to correctly 然后设置新的jupyter内核(上面链接),一切都应该与你指向正确的virtualenv一起工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM