首页 > 解决方案 > SPSS 22 中的 Numpy

问题描述

我在Linux Mint 20 Ulyana(内核 5.4.0-62-generic x86_64 GNU/Linux)下运行SPSS 22.0.0.1(64 位版本)。现在我想使用“私人”SPSS python 版本未附带的 python 模型。

我的 SPSS 版本附带的私有 Python 版本是2.7.1。从 SPSS 语法运行下面的代码给出了私有 python 版本。

* SPSS syntax .
begin program . 
import sys 
print(sys.version) 
end program . 

输出:

2.7.1 (r271:86832, Jun 14 2013, 00:22:41) 
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] 

携带我要使用的模块的系统 python 是2.7.8

~$ python2.7

输出:

Python 2.7.18 (default, Aug  4 2020, 11:16:42) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

据我了解,我可以在指向系统python的私有python中添加一个sitecustomize.py 。该文件的内容只是:

import sys
sys.path.append(r"/usr/lib/python2.7/dist-packages")

这似乎将所需的路径添加到我的私有 python 中。列出来自 SPSS 语法的路径(输出的最后一行):

* SPSS syntax .
begin program . 
import sys 
for p in sys.path: 
  print(p) 
end program . 

输出:

/opt/IBM/SPSS/Statistics/22/extensions 
/home/[USER]/.IBM/SPSS/Statistics/22/extensions 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7/site-packages/readline-6.1.0-py2.7-linux-x86_64.egg 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7/site-packages 
/opt/IBM/SPSS/Statistics/22/Python/lib/python27.zip 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7/plat-linux2 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7/lib-tk 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7/lib-old 
/opt/IBM/SPSS/Statistics/22/Python/lib/python2.7/lib-dynload 
/usr/lib/python2.7/dist-packages

但是,当我尝试在我的 SPSS 语法中导入 numpy 时,我收到了这个非常逐字的消息:

* SPSS syntax .
begin program . 
import numpy 
end program . 

输出:

Traceback (most recent call last): 
File "<string>", line 2, in <module> 
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 142, in <module>
  from . import core 
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 71, in <module> 
  raise ImportError(msg) 
ImportError: 

    IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! 

Importing the multiarray numpy extension module failed.  Most 
likely you are trying to import a failed build of numpy. 
Here is how to proceed: 
- If you're working with a numpy git repository, try `git clean -xdf` 
  (removes all files not under version control) and rebuild numpy. 
- If you are simply trying to use the numpy version that you have installed: 
  your installation is broken - please reinstall numpy. 
- If you have already reinstalled and that did not fix the problem, then: 
  1. Check that you are using the Python you expect (you're using ), 
     and that you have no directories in your PATH or PYTHONPATH that can 
     interfere with the Python and numpy versions you're trying to use. 
  2. If (1) looks fine, you can open a new issue at 
     https://github.com/numpy/numpy/issues.  Please include details on: 
     - how you installed Python 
     - how you installed numpy 
     - your operating system 
     - whether or not you have multiple versions of Python installed 
     - if you built from source, your compiler versions and ideally a build log 
 
     Note: this error has many possible causes, so please don't comment on 
     an existing issue about this - open a new one instead. 

Original error was: No module named _multiarray_umath 

我也试过直接在SPSS语法中添加系统python路径,但是不爱...

* SPSS syntax .
begin program .
import sys
sys.path.insert(0, "/usr/lib/python2.7/dist-packages")

import numpy
end program .

SPSS 在私有 python 上运行良好。系统 python 可以自己正常工作。

标签: pythonspss

解决方案


您需要“告诉” SPSS 使用您的系统 Python。请注意,SPSS 22 只能使用 python 2.7(不能使用其他版本的 2.x,也不能使用 3.x)。所以你需要在你的系统上安装它。然后,在 SPSS 中,转到Edit/Options/File locations并将 Python 2.7 位置设置为您的 system-Python 安装文件夹。您将能够从 SPSS 语法中使用系统 Python 中可用的库。

或者,您可以进入 SPSS-python,并使用pip.


推荐阅读