Problems with installing Pystan in Python 3.10 on Ubuntu 20.04 LTS

I have troubles installing Pystan in Python 3.10 on my Ubuntu 20.04 system. I have already tried all the possible troubleshooting, as well as e.g. a similar issue (Error installing Pystan in python 3.10 with gcc 9.2.0).

This is the error message I receive when I run the following command: sudo pip install pystan

Building wheels for collected packages: pysimdjson
  Building wheel for pysimdjson (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      /home/anvlo/PycharmProjects/PhD/venv/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      /home/anvlo/PycharmProjects/PhD/venv/lib/python3.10/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
        warnings.warn(
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-310
      creating build/lib.linux-x86_64-cpython-310/simdjson
      copying simdjson/__init__.py -> build/lib.linux-x86_64-cpython-310/simdjson
      running build_ext
      building 'csimdjson' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/simdjson
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/tmp/pip-install-1dmgbq2u/pysimdjson_aa6a3887b90247e2bca76445194b5d1f/.eggs/pybind11-2.10.0-py3.10.egg/pybind11/include -I/home/anvlo/PycharmProjects/PhD/venv/include -I/usr/include/python3.10 -c simdjson/binding.cpp -o build/temp.linux-x86_64-cpython-310/simdjson/binding.o -std=c++11
      In file included from /tmp/pip-install-1dmgbq2u/pysimdjson_aa6a3887b90247e2bca76445194b5d1f/.eggs/pybind11-2.10.0-py3.10.egg/pybind11/include/pybind11/detail/../attr.h:13,
                       from /tmp/pip-install-1dmgbq2u/pysimdjson_aa6a3887b90247e2bca76445194b5d1f/.eggs/pybind11-2.10.0-py3.10.egg/pybind11/include/pybind11/detail/class.h:12,
                       from /tmp/pip-install-1dmgbq2u/pysimdjson_aa6a3887b90247e2bca76445194b5d1f/.eggs/pybind11-2.10.0-py3.10.egg/pybind11/include/pybind11/pybind11.h:13,
                       from simdjson/binding.cpp:7:
      /tmp/pip-install-1dmgbq2u/pysimdjson_aa6a3887b90247e2bca76445194b5d1f/.eggs/pybind11-2.10.0-py3.10.egg/pybind11/include/pybind11/detail/../detail/common.h:212:10: fatal error: Python.h: No such file or directory
        212 | #include <Python.h>
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pysimdjson
  Running setup.py clean for pysimdjson
Failed to build pysimdjson
Installing collected packages: pysimdjson, clikit, httpstan, pystan
  Attempting uninstall: pysimdjson
    Found existing installation: pysimdjson 5.0.2
    Uninstalling pysimdjson-5.0.2:
      Successfully uninstalled pysimdjson-5.0.2
  Running setup.py install for pysimdjson ... error

I have already tried to install Cmake, I have updated pip, setuptools, tried downloading pystan in python 3.9, all render the same error.

Thanks in advance for the help!

You need to compile httpstan from source and after it has been installed you can install pystan.

Do you have C++ toolchain installed?

Thanks for the fast reply! Could you give little more information on how to proceed? I have installed httpstan (python3 -m pip install httpstan) or is this not how to install it from source? I googled for C++ toolchain but no concrete instructions popped up.

C++ toolchain

sudo apt-get update
sudo apt-get install build-essential
gcc --version

Then follow Installation — httpstan 4.8.2 documentation

C++ toolchain installment worked. It feels like with every error I resolve, I get 10 new ones:

python3 -m pip install poetry make , worked

But soon I get the following errors:

anvlo@bystre21:~$ python3 -m poetry build
cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

anvlo@bystre21:~$ python3 -m pip install dist/*.whl
Defaulting to user installation because normal site-packages is not writeable
WARNING: Requirement 'dist/*.whl' looks like a filename, but the file does not exist
ERROR: *.whl is not a valid wheel filename.

Hi,

You are not far from ready.

Ok that certainly is an error

In python 3.10 is should be collections.abc.Mapping.

I wonder what library causes that error. Was there a longer exception message? I did not find that part in our codebase.

cc @ariddell

No, everything that popped up I put here. I have tried to resolve the problem but no luck so far.

I think this works on Ubuntu 20.04.

sudo apt install python3-pip
python3 -m pip install -U pip
python3 -m pip install pystan

You do not need to install httpstan from source.

Reading my own notes here: Ubuntu 20.04 cannot install httpstan's manylinux_2_24_x86_64 wheel ("No matching distribution found") · Issue #323 · stan-dev/pystan · GitHub

Update: Just verified this. Everything works on Ubuntu 20.04. httpstan-4.8.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl downloaded and installed, as it should.

I’ve tried this just now but still the same, original error is given when I try the commands. Thanks again for all your time and effort…

The problem is with the python 3.10.

Could you try with 3.9?

We need to figure out where is that error coming from.

I have no problems with Python 3.10 on Ubuntu 20.04 LTS. I’m using the deadsnakes ppa to get Python 3.10. Index of /deadsnakes/ppa/ubuntu

Looks like the issue might be with pysimdjson. For some reason I end up with pysimdjson==3.2.0 when I pip install pystan on Ubuntu 20.04. @avdvloet , I’m not sure why your system is trying to install a different version.

1 Like

I succeeded in installing Pystan without any problems when I created a venv where I downgraded to Python 3.9. For this I used the following commands from @ariddell :

sudo apt install python3-pip
python3 -m pip install -U pip
python3 -m pip install pystan

For now there is no real need for me to work in Python 3.10, 3.9 will work just fine. Thank you again for all the help and feedback!

2 Likes