Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ipython %matplotlib gives "ImportError: No module named moves" despite having moves installed via pip

This one is driving me crazy. I have searched the internet for clues but non of the many threads of the type "ImportError: No module named xxxxxx" has proven very useful.

I had previously Python2.7 installed.

Then I installed Anaconda python, added $HOME/anaconda/bin to the PATH and launched ipython notebook

Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34) 
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

[TerminalIPythonApp] Loading IPython extension: storemagic

Everything works until running the magic %matplotlib inline which generates the following error message:

In [5]: %matplotlib inline
Reloading __future__
Reloading six
Reloading functools
Reloading _functools
Reloading itertools
Reloading operator
Reloading types
Reloading StringIO
Reloading errno
Reloading matplotlib
Reloading distutils
Reloading distutils.version
Reloading distutils.string
Reloading string
Reloading re
Reloading sre_compile
Reloading _sre
Reloading sre_parse
Reloading sre_constants
Reloading _locale
Reloading copy_reg
Reloading strop
Reloading distutils.re
Reloading distutils.types
Reloading dateutil
Reloading pyparsing
Reloading weakref
Reloading UserDict
Reloading _abcoll
Reloading abc
Reloading _weakrefset
Reloading _weakref
Reloading exceptions
Reloading copy
Reloading org
Reloading warnings
Reloading linecache
Reloading os
Reloading posix
Reloading posixpath
Reloading stat
Reloading genericpath
Reloading _warnings
Reloading collections
Reloading _collections
Reloading keyword
Reloading heapq
Reloading _heapq
Reloading thread
Reloading pprint
Reloading cStringIO
Reloading urllib
Reloading socket
Reloading _socket
Reloading _ssl
Reloading time
Reloading base64
Reloading struct
Reloading _struct
Reloading binascii
Reloading urlparse
Reloading ssl
Reloading textwrap
Reloading contextlib
Reloading _scproxy
Reloading urllib.request
Reloading urllib2
Reloading hashlib
Reloading _hashlib
Reloading httplib
Reloading array
Reloading mimetools
Reloading tempfile
Reloading io
Reloading _io
Reloading random
Reloading math
Reloading _random
Reloading fcntl
Reloading rfc822
Reloading bisect
Reloading _bisect
Reloading distutils.sysconfig
Reloading distutils.os
Reloading distutils.sys
Reloading distutils.distutils
Reloading distutils.errors
Reloading matplotlib.cbook
Reloading six.moves
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-1e0aba8000a6> in <module>()

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2305         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2306         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2307         return self.run_line_magic(magic_name, magic_arg_s)
   2308 
   2309     #-------------------------------------------------------------------------

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2226                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2227             with self.builtin_trap:
-> 2228                 result = fn(*args,**kwargs)
   2229             return result
   2230 

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in matplotlib(self, line)

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in matplotlib(self, line)
     86         """
     87         args = magic_arguments.parse_argstring(self.matplotlib, line)
---> 88         gui, backend = self.shell.enable_matplotlib(args.gui)
     89         self._show_matplotlib_backend(args.gui, backend)
     90 

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
   3099                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   3100 
-> 3101         pt.activate_matplotlib(backend)
   3102         pt.configure_inline_support(self, backend)
   3103 

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in activate_matplotlib(backend)
    273 
    274     import matplotlib.pyplot
--> 275     matplotlib.pyplot.switch_backend(backend)
    276 
    277     # This must be imported last in the matplotlib series, after

/Users/mtoots/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.pyc in switch_backend(newbackend)
    131     close('all')
    132     global _backend_mod, new_figure_manager, draw_if_interactive, _show
--> 133     matplotlib.use(newbackend, warn=False, force=True)
    134     from matplotlib.backends import pylab_setup
    135     _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()

/Users/mtoots/anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in use(arg, warn, force)
   1331     # module import. See backends/__init__.py for more detail.
   1332     if need_reload:
-> 1333         reload(sys.modules['matplotlib.backends'])
   1334 
   1335 def get_backend():

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in reload(module, exclude)
    339     try:
    340         with replace_import_hook(deep_import_hook):
--> 341             return deep_reload_hook(module)
    342     finally:
    343         found_now = {}

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in deep_reload_hook(m)
    309 
    310     try:
--> 311         newm = imp.load_module(name, fp, filename, stuff)
    312     except:
    313          # load_module probably removed name from modules because of

/Users/mtoots/anaconda/lib/python2.7/site-packages/matplotlib/backends/__init__.pyc in <module>()
      4 import six
      5 
----> 6 import matplotlib
      7 import inspect
      8 import warnings

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in deep_import_hook(name, globals, locals, fromlist, level)
    250     parent, buf = get_parent(globals, level)
    251 
--> 252     head, name, buf = load_next(parent, None if level < 0 else parent, name, buf)
    253 
    254     tail = head

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in load_next(mod, altmod, name, buf)
    154     buf += subname
    155 
--> 156     result = import_submodule(mod, subname, buf)
    157     if result is None and mod != altmod:
    158         result = import_submodule(altmod, subname, subname)

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in import_submodule(mod, subname, fullname)
    199 
    200         try:
--> 201             m = imp.load_module(fullname, fp, filename, stuff)
    202         except:
    203             # load_module probably removed name from modules because of

/Users/mtoots/anaconda/lib/python2.7/site-packages/matplotlib/__init__.pyc in <module>()
    178 # cbook must import matplotlib only within function
    179 # definitions, so it is safe to import from it here.
--> 180 from matplotlib.cbook import is_string_like
    181 from matplotlib.compat import subprocess
    182 

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in deep_import_hook(name, globals, locals, fromlist, level)
    254     tail = head
    255     while name:
--> 256         tail, name, buf = load_next(tail, tail, name, buf)
    257 
    258     # If tail is None, both get_parent and load_next found

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in load_next(mod, altmod, name, buf)
    154     buf += subname
    155 
--> 156     result = import_submodule(mod, subname, buf)
    157     if result is None and mod != altmod:
    158         result = import_submodule(altmod, subname, subname)

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in import_submodule(mod, subname, fullname)
    199 
    200         try:
--> 201             m = imp.load_module(fullname, fp, filename, stuff)
    202         except:
    203             # load_module probably removed name from modules because of

/Users/mtoots/anaconda/lib/python2.7/site-packages/matplotlib/cbook.pyc in <module>()
     11 
     12 import six
---> 13 from six.moves import xrange, zip
     14 from itertools import repeat
     15 

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in deep_import_hook(name, globals, locals, fromlist, level)
    254     tail = head
    255     while name:
--> 256         tail, name, buf = load_next(tail, tail, name, buf)
    257 
    258     # If tail is None, both get_parent and load_next found

/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/lib/deepreload.pyc in load_next(mod, altmod, name, buf)
    161 
    162     if result is None:
--> 163         raise ImportError("No module named %.200s" % name)
    164 
    165     return result, next, buf

ImportError: No module named moves

Running conda list gives the following list of installed packages

/Users/mtoots> conda list
# packages in environment at /Users/mtoots/anaconda:
#
_license                  1.1                      py27_0  
abstract-rendering        0.5.1                np19py27_0  
anaconda                  2.2.0                np19py27_0  
appscript                 1.0.1                    py27_0  
argcomplete               0.8.4                    py27_0  
astropy                   1.0.1                np19py27_0  
backports.ssl-match-hostname 3.4.0.2                   <pip>
bcolz                     0.8.1                np19py27_0  
beautiful-soup            4.3.2                    py27_0  
beautifulsoup             3.2.1                     <pip>
beautifulsoup4            4.3.2                     <pip>
binstar                   0.10.1                   py27_3  
bitarray                  0.8.1                    py27_0  
blaze                     0.7.3                     <pip>
blaze-core                0.7.3                np19py27_0  
blz                       0.6.2                np19py27_0  
bokeh                     0.8.1                np19py27_1  
boto                      2.36.0                   py27_0  
cdecimal                  2.3                      py27_0  
certifi                   14.05.14                 py27_0  
cffi                      0.9.2                    py27_0  
clyent                    0.3.4                    py27_0  
colorama                  0.3.3                    py27_0  
conda                     3.12.0                   py27_0  
conda-build               1.11.0                   py27_0  
conda-env                 2.1.4                    py27_0  
configobj                 5.0.6                    py27_0  
cryptography              0.8                      py27_0  
curl                      7.38.0                        0  
cython                    0.22                     py27_0  
cytoolz                   0.7.2                    py27_0  
datashape                 0.4.4                np19py27_1  
dateutil                  2.4.1                    py27_0  
decorator                 3.4.0                    py27_0  
docutils                  0.12                     py27_0  
dynd-python               0.6.5                np19py27_0  
enum34                    1.0.4                    py27_0  
fastcache                 1.0.2                    py27_0  
filechunkio               1.6                       <pip>
flask                     0.10.1                   py27_1  
freetype                  2.5.2                         1  
funcsigs                  0.4                      py27_0  
futures                   2.2.0                    py27_0  
gevent                    1.0.1                    py27_0  
gevent-websocket          0.9.3                    py27_0  
greenlet                  0.4.5                    py27_0  
grin                      1.2.1                    py27_1  
h5py                      2.4.0                np19py27_0  
hdf5                      1.8.14                        0  
ipython                   3.1.0                    py27_0  
ipython-notebook          3.0.0                    py27_1  
ipython-qtconsole         3.0.0                    py27_0  
itsdangerous              0.24                     py27_0  
jdcal                     1.0                      py27_0  
jedi                      0.8.1                    py27_0  
jinja2                    2.7.3                    py27_1  
jpeg                      8d                            1  
jsonschema                2.4.0                    py27_0  
launcher                  1.0.0                         2  
libdynd                   0.6.5                         0  
libpng                    1.5.13                        1  
libsodium                 0.4.5                         0  
libtiff                   4.0.2                         1  
libxml2                   2.9.0                         1  
libxslt                   1.1.28                        2  
llvmlite                  0.2.2                    py27_1  
lxml                      3.4.2                    py27_0  
markupsafe                0.23                     py27_0  
matplotlib                1.4.3                np19py27_1  
mistune                   0.5.1                    py27_0  
mock                      1.0.1                    py27_0  
moves                     0.1                       <pip>
mrjob                     0.4.4                     <pip>
multipledispatch          0.4.7                    py27_0  
networkx                  1.9.1                    py27_0  
nltk                      3.0.2                np19py27_0  
node-webkit               0.10.1                        0  
nose                      1.3.4                    py27_1  
numba                     0.17.0               np19py27_0  
numexpr                   2.3.1                np19py27_0  
numpy                     1.9.2                    py27_0  
odo                       0.3.1                np19py27_0  
openpyxl                  1.8.5                    py27_0  
openssl                   1.0.1k                        1  
pandas                    0.15.2               np19py27_1  
patsy                     0.3.0                np19py27_0  
pattern                   2.6                       <pip>
pep8                      1.6.2                    py27_0  
pillow                    2.7.0                    py27_1  
pip                       6.1.1                    py27_0  
ply                       3.4                      py27_0  
psutil                    2.2.1                    py27_0  
ptyprocess                0.4                      py27_0  
py                        1.4.26                   py27_0  
pyasn1                    0.1.7                    py27_0  
pyaudio                   0.2.7                    py27_0  
pycosat                   0.6.1                    py27_0  
pycparser                 2.10                     py27_0  
pycrypto                  2.6.1                    py27_0  
pycurl                    7.19.5.1                 py27_0  
pyflakes                  0.8.1                    py27_0  
pygments                  2.0.2                    py27_0  
pyopenssl                 0.14                     py27_0  
pyparsing                 2.0.3                    py27_0  
pyqt                      4.11.3                   py27_0  
pytables                  3.1.1                np19py27_2  
pytest                    2.6.4                    py27_0  
python                    2.7.9                         1  
python-dateutil           2.4.2                    py27_0  
python.app                1.2                      py27_3  
pytz                      2015.2                   py27_0  
pyyaml                    3.11                     py27_0  
pyzmq                     14.5.0                   py27_0  
qt                        4.8.6                         0  
readline                  6.2                           2  
redis                     2.6.9                         0  
redis-py                  2.10.3                   py27_0  
requests                  2.7.0                    py27_0  
rope                      0.9.4                    py27_1  
runipy                    0.1.3                    py27_0  
scikit-image              0.11.2               np19py27_0  
scikit-learn              0.15.2               np19py27_0  
scipy                     0.15.1               np19py27_0  
seaborn                   0.5.1                     <pip>
setuptools                15.2                     py27_0  
simplejson                3.6.5                     <pip>
sip                       4.16.5                   py27_0  
six                       1.9.0                    py27_0  
sockjs-tornado            1.0.1                    py27_0  
sphinx                    1.2.3                    py27_0  
spyder                    2.3.4                    py27_1  
spyder-app                2.3.4                    py27_0  
sqlalchemy                0.9.9                    py27_0  
sqlite                    3.8.4.1                       1  
ssl_match_hostname        3.4.0.2                  py27_0  
statsmodels               0.6.1                np19py27_0  
sympy                     0.7.6                    py27_0  
tables                    3.1.1                     <pip>
terminado                 0.5                      py27_0  
tk                        8.5.18                        0  
toolz                     0.7.1                    py27_0  
tornado                   4.1                      py27_0  
ujson                     1.33                     py27_0  
unicodecsv                0.9.4                    py27_0  
werkzeug                  0.10.1                   py27_0  
xlrd                      0.9.3                    py27_0  
xlsxwriter                0.6.7                    py27_0  
xlwings                   0.3.4                    py27_0  
xlwt                      0.7.5                    py27_0  
yaml                      0.1.4                         1  
zeromq                    4.0.4                         0  
zlib                      1.2.8                         0  

And sys.path prints the following

In [1]: import sys

In [2]: sys.path
Out[2]: 
['',
 '/Users/mtoots/anaconda/bin',
 '/Users/mtoots/anaconda/lib/python27.zip',
 '/Users/mtoots/anaconda/lib/python2.7',
 '/Users/mtoots/anaconda/lib/python2.7/plat-darwin',
 '/Users/mtoots/anaconda/lib/python2.7/plat-mac',
 '/Users/mtoots/anaconda/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/mtoots/anaconda/lib/python2.7/lib-tk',
 '/Users/mtoots/anaconda/lib/python2.7/lib-old',
 '/Users/mtoots/anaconda/lib/python2.7/lib-dynload',
 '/Users/mtoots/anaconda/lib/python2.7/site-packages',
 '/Users/mtoots/anaconda/lib/python2.7/site-packages/Sphinx-1.2.3-py2.7.egg',
 '/Users/mtoots/anaconda/lib/python2.7/site-packages/aeosa',
 '/Users/mtoots/anaconda/lib/python2.7/site-packages/cryptography-0.8-py2.7-macosx-10.5-x86_64.egg',
 '/Users/mtoots/anaconda/lib/python2.7/site-packages/setuptools-15.2-py2.7.egg',
 '/Users/mtoots/anaconda/lib/python2.7/site-packages/IPython/extensions',
 '/Users/mtoots/.ipython']

What exactly is causing the error here? The moves package seems to be installed and so does six. What does it mean that the moves package in the conda list has <pip> in the third column?

like image 651
Martooc Avatar asked May 13 '15 13:05

Martooc


2 Answers

I suppose you have two ipythons installed, check which of them is running on linux shell:

$ where ipython if you find the the non-anaconda is running, clean the 'pure python' $ sudo pip uninstall ipython and check the path to see if you have the binaries pointing to the anaconda ipython, as in my case, you can see /home/henry/anaconda3/bin $ echo $PATH $ /usr/local/heroku/bin:/home/henry/.cabal/bin:/home/henry/Library/Haskell/bin:/home/henry/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/henry/bin/scala/bin:/home/henry/anaconda3/bin:/home/henry/bin/rebar3

like image 125
Henry H. Avatar answered Oct 30 '22 17:10

Henry H.


I have found another solution to that issue. Mainly, you can comment out/remove just this line from ipython_config.py in profile_default

c.InteractiveShell.deep_reload = True
like image 30
Szymon Roziewski Avatar answered Oct 30 '22 16:10

Szymon Roziewski