Pystan build is not PEP 517 compliant

Please make the build PEP 517 compliant

Package operations: 1 install, 0 updates, 0 removals

  • Installing pystan ( Failed


  Backend subprocess exited when trying to invoke build_wheel
  Cython>=0.22 and NumPy are required.

  at /opt/homebrew/Cellar/poetry/1.6.1/libexec/lib/python3.11/site-packages/poetry/installation/ in _prepare
      144│                 error = ChefBuildError("\n\n".join(message_parts))
      146│             if error is not None:
    → 147│                 raise error from None
      149│             return path
      151│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with pystan ( not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "pystan (=="'.

PyStan 2.x is not supported anymore. Is there a specific reason you need to use it?

more recent versions of pystan require httpstan. httpstan requires x86-64 CPU. i’m using M2 Max with Sonoma 14.0

You can build your own httpstan following Installation — httpstan 4.10.1 documentation

we’re building httpstan in our CI pipelines/locally currently.

installing pystan==3.7.0 is not as simple as pip install on apple silicon, as far as i can tell this is because the build is not PEP 517 compliant.

what would it take to make httpstan/pystan PEP 517 compliant (and any other changes) so it can be simply pip installed on ARM?

have you considered CmdStanPy? cf CmdStanPy 1.0 - #3 by WardBrian

Ok, so PyStan 3.x is not pep complient.

Good question, @ariddell any ideas what are we missing?

First, direct your attention to httpstan – that’s always going to be the issue, not pystan.

You can’t build httpstan automatically from source due to the complicated Makefile. The path to fixing this issues lies with scikit-build, I think. If we use scikit-build we could get everything to build from source via pip install httpstan. But using scikit-build requires rewriting our current build scheme in cmake. I don’t think I’ll have time for this anytime soon. Others are welcome to try.

So for now you have to follow the instructions in the FAQ and build httpstan manually: How can I run pystan on macOS with Apple silicon chips (Apple M1, M2, etc)?

It might be possible to get Apple Silicon wheels using our current setup now that Github Actions has beta support for Apple Silicon runners. But this seems to cost money and probably requires a bit of local experimentation with an Apple Silicon laptop/desktop (to verify that the Github Actions scripts work).

i’d be willing to assist with experimentation on M2 Max and M1 processors

rewriting the current build scheme in cmake – not sure if i’d have time for that. i haven’t used cmake/cpp/c seriously in ~a decade. do you have a rough estimate of how long it’d take for a ~newcomer to rewrite in cmake?

Thanks @er-eis. I wish I knew how much work was involved. It may be possible to have cmake use the existing (complicated) Makefile. If this is possible then switching to scikit-build could be quite easy.

I recently had some success writing cmake configuration for cmdstan and Stan-math:

I suspect this would be viable for PyStan, and would likely even allow it to work on Windows (the above experiment enabled me to compile against the MSVC ABI with the clang-cl compiler)

1 Like

This is great news. I was just thinking about posting a query about this. Having a cmake option for math, in particular, would be wonderful.

There is an issue discussing this possibility here: Allow cmake users to use FetchContent_Declare · Issue #2967 · stan-dev/math · GitHub