0
votes

Cannot import matplotlib with ipython/jupyter notebook through a virtual environment.

I'm able to import matplotlib just fine using the console. Having seen other SO posts I can't seem to get this set up right.

I followed this to get the separate ipython/jupyter kernel.

When I checked my locations through jupyter I get

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'

I am not sure these are correct. Main jupyter error below

---------------------------------------------------------------------------
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
1

1 Answers

0
votes

Ok I fixed this by using the tutorial properly (http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs)

You need to set up a virtualenv, then make sure that you install jupyter within it. I was using the globally installed jupyter.

Then set up the new jupyter kernel (linked above) and everything should work with your virtualenv pointed to correctly