iPython Mac OSX Yosemite 上的笔记本:没有名为 jinja2 的模块,即使已安装

iPython notebook on Mac OSX Yosemite: no module named jinja2, even if it's installed

我正在尝试在 OSX Yosemite 上运行 iPython notebook。我已经通过

安装了所有东西
pip install ipython[all]

我明白了

mattia:~ mattiaspeziali$ pip freeze
backports.ssl-match-hostname==3.4.0.2
certifi==14.5.14
docutils==0.12
gnureadline==6.3.3
ipython==2.3.1
Jinja2==2.7.3
MarkupSafe==0.23
nose==1.3.4
numpy==1.8.2
numpydoc==0.5
pandas==0.14.1
Pygments==2.0.1
pyzmq==14.4.1
Sphinx==1.2.3
tornado==4.0.2
vboxapi==1.0

然而,jinja2 似乎没有正确安装:

    mattia:~ mattiaspeziali$ ipython notebook
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 11, in <module>
    sys.exit(start_ipython())
  File "/Library/Python/2.7/site-packages/IPython/__init__.py", line 120, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 563, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/IPython/terminal/ipapp.py", line 321, in initialize
    super(TerminalIPythonApp, self).initialize(argv)
  File "<string>", line 2, in initialize
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/IPython/core/application.py", line 381, in initialize
    self.parse_command_line(argv)
  File "/Library/Python/2.7/site-packages/IPython/terminal/ipapp.py", line 316, in parse_command_line
    return super(TerminalIPythonApp, self).parse_command_line(argv)
  File "<string>", line 2, in parse_command_line
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 475, in parse_command_line
    return self.initialize_subcommand(subc, subargv)
  File "<string>", line 2, in initialize_subcommand
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 92, in catch_config_error
    return method(app, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/IPython/config/application.py", line 406, in initialize_subcommand
    subapp = import_item(subapp)
  File "/Library/Python/2.7/site-packages/IPython/utils/importstring.py", line 42, in import_item
    module = __import__(package, fromlist=[obj])
  File "/Library/Python/2.7/site-packages/IPython/html/notebookapp.py", line 42, in <module>
    from jinja2 import Environment, FileSystemLoader
ImportError: No module named jinja2

我也尝试卸载并重新安装 jinja2,但没有任何变化。有什么建议吗?

另外:

mattia:~ mattiaspeziali$ which python /usr/local/bin/python

mattia:~ mattiaspeziali$ which ipython /usr/local/bin/ipython

mattia:~ mattiaspeziali$ which pip /usr/local/bin/pip

重新安装 iPython 解决了问题。

我在使用 jinja2+ipython[notebook] 时遇到了同样的问题。 jinja2 似乎对 运行 ipython 终端不是强制性的,默认情况下不安装。

但您必须在 ipython 之前安装它才能打开笔记本。