Numpy.i is missing. What is the recommended way to install it?

I am writing a C ++ library that can be invoked with both C ++ and Python using the SWIG-Python interface. I would like to make some functions in the library to return a numpy array when they are used in Python.

The SWIG documentation [1] says that numpy.iunderneath numpy/docs/swigcan be used for this purpose. But I can not find this directory on the following systems.

  • Scientific Linux 6.4 (RHEL 6.4 clone) + Python 2.6 + NumPy 1.4 (installed via yum)
  • OS X Mavericks + Python 2.7 + NumPy 1.8 (via easy_install)
  • OS X Mavericks + Python 2.7 + NumPy 1.8 (built from source python setup.py install)

In numpy-1.8.0/doc/swigexists numpy.iif I get the source code .tar.gz from the NumPy site. But this file is not installed automatically when executed python setup.py install.

So, I would like to know what is the best or recommended installation method numpy.ion my system.

As I distribute this library to my colleagues, posting numpy.iin my code can be a simple solution. But I'm talking about version mismatch with their NumPy.

[1] http://docs.scipy.org/doc/numpy/reference/swig.interface-file.html

+4
source share
3 answers

, , , numpy.i , Numpy.

numpy.i Numpy C-API, , C .

+4

setup.py numpy.i Github :

import re
import requests
import numpy

np_version = re.compile(r'(?P<MAJOR>[0-9]+)\.'
                        '(?P<MINOR>[0-9]+)') \
                        .search(numpy.__version__)
np_version_string = np_version.group()
np_version_info = {key: int(value)
                   for key, value in np_version.groupdict().items()}

np_file_name = 'numpy.i'
np_file_url = 'https://raw.githubusercontent.com/numpy/numpy/maintenance/' + \
              np_version_string + '.x/tools/swig/' + np_file_name
if(np_version_info['MAJOR'] == 1 and np_version_info['MINOR'] < 9):
    np_file_url = np_file_url.replace('tools', 'doc')

chunk_size = 8196
with open(np_file_name, 'wb') as file:
    for chunk in requests.get(np_file_url,
                              stream=True).iter_content(chunk_size):
        file.write(chunk)

Numpy Python 2, .

+2

, , , - Makefile, numpy.i, . , . ${PROGRAM}: ${PROGRAM}.c:

# put here the root name of your code
PROGRAM = simple

CC  = gcc
CFLAGS  = -c -fPIC -O2  
LFLAGS  = -I/Users/nemmen/anaconda3/include/python3.5m -I/Users/nemmen/anaconda3/lib/python3.5/site-packages/numpy/core/include

all: ${PROGRAM}

${PROGRAM}: ${PROGRAM}.c
    [ -f ./numpy.i ] && echo "numpy.i already here, good" || wget https://raw.githubusercontent.com/numpy/numpy/master/tools/swig/numpy.i

    swig -python -o ${PROGRAM}_wrap.c ${PROGRAM}.i
    $(CC) ${CFLAGS} ${PROGRAM}.c -o ${PROGRAM}.o
    $(CC) ${CFLAGS} ${PROGRAM}_wrap.c -o ${PROGRAM}_wrap.o ${LFLAGS}
    ld -bundle -flat_namespace -undefined suppress -o _${PROGRAM}.so *.o

clean:
    rm -rf *.o *.mod *.so ${PROGRAM}_wrap.c numpy.i __pycache__

, Makefile , repo.

0

Source: https://habr.com/ru/post/1527521/


All Articles