Will Norvelle
Will Norvelle

Reputation: 121

How to properly install a NumPy ufunc?

I am trying to install an example ufunc from the SciPy Docs but when I run python setup.py build or python setup.py install I get a few warnings about a deprecated NumPy API.

When I run python setup.py install this is the output:

$ python setup.py install
running install
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompileroptions
running build_src
build_src
building extension "npufunc_directory.npufunc" sources
build_src: building npy-pkg config files
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'npufunc_directory.npufunc' extension
compiling C sources
C compiler: gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.8-1.x86_64/build=/usr/src/debug/python-2.7.8-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.8-1.x86_64/src/Python-2.7.8=/usr/src/debug/python-2.7.8-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
creating build
creating build/temp.cygwin-1.7.32-x86_64-2.7
compile options: '-I/usr/lib/python2.7/site-packages/numpy/core/include -I/usr/include/python2.7 -c'
gcc: single_type_logit.c
In file included from /usr/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0,
             from single_type_logit.c:3:
/usr/lib/python2.7/site-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp] #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
creating build/lib.cygwin-1.7.32-x86_64-2.7
creating build/lib.cygwin-1.7.32-x86_64-2.7/npufunc_directory
gcc -shared -Wl,--enable-auto-image-base -L. build/temp.cygwin-1.7.32-x86_64-2.7/single_type_logit.o -L/usr/lib/python2.7/config -L/usr/lib -lpython2.7 -o build/lib.cygwin-1.7.32-x86_64-2.7/npufunc_directory/npufunc.dll
running scons
running install_lib
copying build/lib.cygwin-1.7.32-x86_64-2.7/npufunc_directory/npufunc.dll -> /usr/lib/python2.7/site-packages/npufunc_directory
running install_egg_info
Removing /usr/lib/python2.7/site-packages/npufunc_directory-0.0.0-py2.7.egg-info
Writing /usr/lib/python2.7/site-packages/npufunc_directory-0.0.0-py2.7.egg-info
running install_clib
customize UnixCCompiler

running python setup.py build produces:

$ python setup.py build
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "npufunc_directory.npufunc" sources
build_src: building npy-pkg config files
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
running scons

If I try to import the module I get:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import npufunc
ImportError: No module named npufunc

Does anyone know how to make this work?

Upvotes: 4

Views: 911

Answers (1)

Ramon Crehuet
Ramon Crehuet

Reputation: 4017

According to the documentation "The __init__.py files are required to make Python treat the directories as containing packages". The setup.py in the Numpy documentation does not create this file, so Python does not import anything as it ignores this directory.

Solution: just add an empty __init__.py file in the /usr/local/lib/python2.7/dist-packages/npufunc_directory directory, for example with sudo touch __init__.py Then try:

>>> from npufunc_directory import npufunc
>>> npufunc.logit(.5)
0.0

Alternatively, add import npufunc to the __init__.py and then you can do:

>>> import npufunc_directory
>>> npufunc_directory.npufunc.logit(0.5)
0.0

Upvotes: 1

Related Questions