Skip to content

Mark simulator as a cython package in setup.py#6

Open
bgmeulem wants to merge 3 commits intomackelab:mainfrom
bgmeulem:setup-cython
Open

Mark simulator as a cython package in setup.py#6
bgmeulem wants to merge 3 commits intomackelab:mainfrom
bgmeulem:setup-cython

Conversation

@bgmeulem
Copy link
Copy Markdown

@bgmeulem bgmeulem commented Feb 18, 2026

Hiya

This PR proposes to mark pyloric.simulator.pyx as a Cython extension in seutp.py. This helps out some package managers.

I had some issues properly installing this package. I use pixi as a environment manager and front-end to build packages. This did not automatically build the Cython extension. In addition, running python setup.py build_ext also does not build it, since it's not marked as an extension in setup. I didn't check whether or not this issue exists when using pip directly, as advertised in the readme. However, I suspect it's good practice anyways to mark Cython packages as such in the setup.py. I noticed they need the numpy headers to compile the .c file, hence the additional include_dirs argument in setup

@bgmeulem
Copy link
Copy Markdown
Author

bgmeulem commented Feb 18, 2026

After some digging around, I think I understand some additional issues I'm encountering building the Cython module (apart from what's mentioned above i.e. declaring them in setup.py).
I encountered the following additional errors upon importing pyloric.simulator

ImportError: numpy.core.multiarray failed to import (auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; use '<void>numpy._import_array' to disable if you are certain you don't need it)

Can be fixed by simply adding the requested line in simulator.pyx (see ce405c6)

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject`

Seems like numpy changed the C headers to expect ndarrays of size 80 prior to numpy==1.20, size 88 after numpy==1.20 and size 96 god knows when, but likely numpy==2.0. So if you build the thing with a numpy version that is too recent (not unlikely in isolated build environments), or likewise have a numpy version that is rather old in your runtime environment, you will get this mismatch.

Solutions:

  • Version track pyloric to match numpy versions
  • Building the package within your run environment using --no-build-isolation. In this case, the build dependencies in pyproject.toml are ignored, but the package is built using whichever numpy version exists in your environment when you invoke the build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant