如何在Ubuntu 14.04中为python 3工作得到正确的numpy

时间:2015-07-23 10:03:09

标签: ubuntu python-3.x numpy

我使用的是Ubuntu 14.04,它默认安装了python 3。我使用Ubuntu包管理器为python 3安装了numpy和scipy但不是pip:

apt-get install python3-numpy python3-scipy

当我使用python3运行脚本时,似乎它使用了与python 2.7一起安装的numpy:

python3 script.py
Original exception was:
Traceback (most recent call last):
...
line 18, in <module>
    import numpy as np
  File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 6, in <module>
    from . import multiarray
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: _Py_ZeroStruct

我不想搞砸python2.7和python3以及那些相应的numpy和scipy。考虑到我为python3安装numpy的方式,如何设置python3使用其numpy的指针?

1 个答案:

答案 0 :(得分:0)

在同一台机器上处理多个版本的python可能会很棘手。大多数人会建议您使用虚拟环境。但是快速解决方法是只需添加你想要的python版本:

pip3 install numpy scipy

这将全局安装包。

参考: pip: dealing with multiple Python versions?