setup.py with cython source in subpackage

1,290 views
Skip to first unread message

Pablo d'Angelo

unread,
Dec 6, 2010, 4:17:17 AM12/6/10
to cython-users
Hi all,

I'm trying to create a python like distribution of my "adjust"
package, which includes a single cython file (in the adjust
subdirectory), and I'm trying to follow the example in the manual.

Unfortunlatey, building the cython file failes.

-------------------------------------------------------------------------
python setup.py build_ext --inplace
running build_ext
cythoning adjust/solvers_opt.pyx to adjust/solvers_opt.c

Error converting Pyrex file to C:
------------------------------------------------------------
...

^
------------------------------------------------------------

/home/angelo/soft/adjust-xdib/adjust/solvers_opt.pyx:1:0: 'adjust/
solvers_opt' is not a valid module name
building 'adjust/solvers_opt' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -
Wstrict-prototypes -fPIC -I/usr/lib/python2.6/dist-packages/numpy/core/
include -I/usr/include/python2.6 -c adjust/solvers_opt.c -o build/
temp.linux-x86_64-2.6/adjust/solvers_opt.o
adjust/solvers_opt.c:1: error: #error Do not use this file, it is the
result of a failed Cython compilation.
error: command 'gcc' failed with exit status 1
-------------------------------------------------------------------------

I'm using cython 0.12.1 on Ubuntu 10.10

I can invoke cython adjust/solvers_opt.py manually, and then the build
picks up the generated *.c file and succeeds. (Or should I just ship
the cython generated *.c code in the source package?)

Here is the (parital) overview of the directory structure:

setup.py
adjust/__init__.py
adust/*.py
adjust/solvers_opt.pyx

setup.py looks like this:

-------------------------------------------------------------------------
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np

ext_modules = [Extension("adjust/solvers_opt", ["adjust/
solvers_opt.pyx"])]

setup(
name = 'adjust',
version = '0.1',
description = 'adjustment library',
author = "Pablo d'Angelo",
author_email = "pablo....@web.de",
install_requires = ['numpy', 'scipy'],
license = "BSD",
packages = ['adjust'],
scripts=['rpc_bundle', 'rpc_bundle_p5'],
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
include_dirs = [np.get_include()]
)
-------------------------------------------------------------------------

Robert Bradshaw

unread,
Dec 6, 2010, 1:45:21 PM12/6/10
to cython...@googlegroups.com
On Mon, Dec 6, 2010 at 1:17 AM, Pablo d'Angelo <pablo....@web.de> wrote:
> Hi all,
>
> I'm trying to create a python like distribution of my "adjust"
> package, which includes a single cython file (in the adjust
> subdirectory), and I'm trying to follow the example in the manual.
>
> Unfortunlatey, building the cython file failes.
>
> -------------------------------------------------------------------------
> python setup.py build_ext --inplace
> running build_ext
> cythoning adjust/solvers_opt.pyx to adjust/solvers_opt.c
>
> Error converting Pyrex file to C:
> ------------------------------------------------------------
> ...
>
> ^
> ------------------------------------------------------------
>
> /home/angelo/soft/adjust-xdib/adjust/solvers_opt.pyx:1:0: 'adjust/
> solvers_opt' is not a valid module name

The module should be named "adjust.solvers_opt" in your setup.py.

Pablo d'Angelo

unread,
Dec 6, 2010, 11:59:34 PM12/6/10
to cython-users
Hi Robert,

> The module should be named "adjust.solvers_opt" in your setup.py.

Thanks, that does the trick! This is my first encounter with
distutils, so sorry if this was an obvious question.

ciao
Pablo
Reply all
Reply to author
Forward
0 new messages