ipython notebook 不能导入numpy


我在server上安装了ipython notebook。启动后import numpy报如下异常:


 ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-5a0bd626bb1d> in <module>()
----> 1 import numpy

/home/users/kuangzhexi/.jumbo/lib/python2.7/site-packages/numpy/__init__.py in <module>()
151         return loader(*packages, **options)
152 
--> 153     from . import add_newdocs
154     __all__ = ['add_newdocs', 'ModuleDeprecationWarning']
155 

/home/users/kuangzhexi/.jumbo/lib/python2.7/site-packages/numpy/add_newdocs.py in <module>()
 11 from __future__ import division, absolute_import, print_function
 12 
---> 13 from numpy.lib import add_newdoc
 14 
 15 ###############################################################################

/home/users/kuangzhexi/.jumbo/lib/python2.7/site-packages/numpy/lib/__init__.py in <module>()
 15 from .ufunclike import *
 16 
---> 17 from . import scimath as emath
 18 from .polynomial import *
 19 #import convertcode

ImportError: cannot import name scimath

我看了stackoverflow如下两个答案:
http://stackoverflow.com/questions/26238004/ipython-notebook-throws-importerror-ipython-doesnt
http://stackoverflow.com/questions/15514593/importerror-no-module-named-when-trying-to-run-python-script/15622021#15622021
我的操作是:
sys.path.append('/home/users/kuangzhexi/.jumbo/lib/python2.7/site-packages/numpy/lib')
sys.path.append('/home/users/kuangzhexi/.jumbo/lib/python2.7/site-packages/numpy/')
但是还是不行。

ipython python numpy

WingHCC 10 years, 11 months ago

不要乱改 sys.path。一般建议直接安装系统软件源里的包。如果嫌旧了,自己安装也安装到标准路径,这样不需要自己折腾。

看你的情况,你应该把 '/home/users/kuangzhexi/.jumbo/lib/python2.7/site-packages' 加入到 sys.path。下边有个 numpy 目录,就是你的 numpy 包了。

chuenyi answered 10 years, 11 months ago

Your Answer