Ipython笔记本。Windows 7中%pylab加载错误

1 投票
4 回答
1499 浏览
提问于 2025-04-17 15:17

我在使用Windows 7,安装的是Enthought Python Distribution 7.3-2 Academic版本。
我打开了命令提示符,切换到我的代码目录,然后输入了

U:\rsch>ipython notebook

在新打开的笔记本里,我输入了 %pylab,结果出现了以下错误:

In [1]: %pylab

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
U:\rsch\<ipython-input-1-5c1faa999e5b> in <module>()
----> 1 get_ipython().magic(u'pylab')

D:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, arg_s, next_input)
   1983                 self._magic_locals = sys._getframe(1).f_locals
   1984             with self.builtin_trap:
-> 1985                 result = fn(magic_args)
   1986             # Ensure we're not keeping object references around:

   1987             self._magic_locals = {}

D:\Python27\lib\site-packages\IPython\core\magic.pyc in magic_pylab(self, s)
   3471             import_all_status = True
   3472 
-> 3473         self.shell.enable_pylab(s, import_all=import_all_status)
   3474 
   3475     def magic_tb(self, s):

D:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in enable_pylab(self, gui, import_all)
   2592         ns = {}
   2593         try:
-> 2594             gui = pylab_activate(ns, gui, import_all, self)
   2595         except KeyError:
   2596             error("Backend %r not supported" % gui)

D:\Python27\lib\site-packages\IPython\core\pylabtools.pyc in pylab_activate(user_ns, gui, import_all, shell)
    327     itself, and will be needed next to configure IPython's gui integration.
    328     """
--> 329     gui, backend = find_gui_and_backend(gui)
    330     activate_matplotlib(backend)
    331     import_pylab(user_ns, import_all)

D:\Python27\lib\site-packages\IPython\core\pylabtools.pyc in find_gui_and_backend(gui)
    194     """
    195 
--> 196     import matplotlib
    197 
    198     if gui and gui != 'auto':

D:\Python27\lib\site-packages\matplotlib\__init__.py in <module>()
    131 import sys, os, tempfile
    132 
--> 133 from matplotlib.rcsetup import (defaultParams,
    134                                 validate_backend,
    135                                 validate_toolbar,

D:\Python27\lib\site-packages\matplotlib\rcsetup.py in <module>()
     17 import warnings
     18 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
---> 19 from matplotlib.colors import is_color_like
     20 
     21 #interactive_bk = ['gtk', 'gtkagg', 'gtkcairo', 'fltkagg', 'qtagg', 'qt4agg',


D:\Python27\lib\site-packages\matplotlib\colors.py in <module>()
     50 """
     51 import re
---> 52 import numpy as np
     53 from numpy import ma
     54 import matplotlib.cbook as cbook

D:\Python27\lib\site-packages\numpy\__init__.pyc in <module>()
    141         return loader(*packages, **options)
    142 
--> 143     import add_newdocs
    144     __all__ = ['add_newdocs']
    145 

D:\Python27\lib\site-packages\numpy\add_newdocs.py in <module>()
      7 #       core/fromnumeric.py, core/defmatrix.py up-to-date.

      8 
----> 9 from numpy.lib import add_newdoc
     10 
     11 ###############################################################################


D:\Python27\lib\site-packages\numpy\lib\__init__.py in <module>()
     11 
     12 import scimath as emath
---> 13 from polynomial import *
     14 #import convertcode

     15 from utils import *

D:\Python27\lib\site-packages\numpy\lib\polynomial.py in <module>()
     15 from numpy.lib.function_base import trim_zeros, sort_complex
     16 from numpy.lib.type_check import iscomplex, real, imag
---> 17 from numpy.linalg import eigvals, lstsq
     18 
     19 class RankWarning(UserWarning):

D:\Python27\lib\site-packages\numpy\linalg\__init__.py in <module>()
     46 from info import __doc__
     47 
---> 48 from linalg import *
     49 
     50 from numpy.testing import Tester

D:\Python27\lib\site-packages\numpy\linalg\linalg.py in <module>()
     21         isfinite, size, finfo, absolute, log, exp
     22 from numpy.lib import triu
---> 23 from numpy.linalg import lapack_lite
     24 from numpy.matrixlib.defmatrix import matrix_power
     25 from numpy.compat import asbytes

ImportError: DLL load failed: The specified path is invalid.

我不知道该怎么办。谢谢。

4 个回答

0

EPD是和ipython 0.12一起发布的。从那以后,ipython已经发展了很多。你应该通过输入“enpkg ipython”来更新到ipython 0.13.1,具体的步骤可以在这里找到: https://support.enthought.com/entries/22415022-Using-enpkg-to-update-EPD-packages

0

很可能你的系统路径里缺少了Scripts这个文件夹。你可以通过命令提示符来检查一下,运行

echo %PATH%

然后看看里面有没有 D:\Python27\Scripts 这个路径。如果没有的话,你可以手动添加它,可以通过控制面板来添加,或者使用像 Rapid Environment Editor 这样的工具。

1

我也遇到过同样的问题,这里是我解决的方法:

  1. 我确保在启动IPython的时候使用"pylab"。
  2. 然后我确保所有的会话/实例(抱歉,我还是新手 :))都关闭了。你可以通过在所有终端按下ctrl-C来关闭它们,如果在Notebook的仪表盘上有“关闭”选项,也可以点击它。

可能还有更好的方法来解决这个问题,但这是我用过的有效方法。

开发者们,请注意,很多新手在第一次运行笔记本时遇到错误可能会感到非常沮丧。

亚当

撰写回答