Numpy in SPSS 22

Viewed 243

I'm running SPSS 22.0.0.1 (64 bit edition) under Linux Mint 20 Ulyana (kernel 5.4.0-62-generic x86_64 GNU/Linux). Now I want to use python models not shipped with the "private" SPSS python edition.

The private Python version shipped with my version of SPSS is 2.7.1. Running the code below from SPSS syntax gives the private python version.

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

outputs:

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

The system python that carries the modules I want use is 2.7.8.

~$ python2.7

outputs:

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.
>>> 

From what I understand, I can add a sitecustomize.py in the private python that points to the system python. The content of the file is just:

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

This seems to add the desired path to my private python. Listing the paths from SPSS syntax (last row of output):

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

outputs:

/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

However, when I try to import numpy in my SPSS syntax, I get this quite verbatim message:

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

outputs:

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 

I also tried to add the system python path directly in SPSS syntax, but no love...

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

import numpy
end program .

SPSS is working fine with the private python. And the system python is working fine on its own.

1 Answers

You need to "tell" SPSS to use your system-Python. Be aware that SPSS 22 can only use python 2.7 (not other version of 2.x, and no 3.x). So you need to have that installed on your system. Then, in SPSS, go to Edit/Options/File locations, and set the Python 2.7 location to your system-Python installation folder. You will be able to use, from SPSS syntax, the libraries available in your system-Python.

Alternatively, you could go into your SPSS-python, and install the needed libraries with pip.

Related