Could not build whells for pybluez, which is required to install pyproject.toml-based projects

319 Views Asked by At

I am trying to install the pybluez package, however I am getting the same error as I already had gotten while trying to install btzen, which then I just skipped. here is what my terminal looks like so far;

$ pip install pybluez --break-system-packages
Defaulting to user installation because normal site-packages is not writeable
Collecting pybluez
  Using cached PyBluez-0.23.tar.gz (97 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pybluez
  Building wheel for pybluez (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/kaustubhpawar/.local/lib/python3.11/site-packages/setuptools/_distutils/dist.py:275: UserWarning: Unknown distribution option: 'use_2to3'
        warnings.warn(msg)
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.11
      creating build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/msbt.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/bluez.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/btcommon.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/macos.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/__init__.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/widcomm.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/ble.py -> build/lib.linux-x86_64-3.11/bluetooth
      running build_ext
      creating build/temp.linux-x86_64-3.11
      creating build/temp.linux-x86_64-3.11/bluez
      x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -g -fwrapv -O2 -fPIC -I./port3 -I/usr/include/python3.11 -c bluez/btmodule.c -o build/temp.linux-x86_64-3.11/bluez/btmodule.o
      In file included from bluez/btmodule.c:20:
      bluez/btmodule.h:5:10: fatal error: bluetooth/bluetooth.h: No such file or directory
          5 | #include <bluetooth/bluetooth.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 pybluez
  Running setup.py clean for pybluez
Failed to build pybluez
ERROR: Could not build wheels for pybluez, which is required to install pyproject.toml-based projects

Also I am using the pip3 for this.

I already tried getting the pip package for wheels but that didn't work at all. So I am at a roadblock right now.

Also I tried installing the libbluetooth-dev library like the top answers says, which did clear something up, but not a whole lot. Here is the newer error that I got.

Defaulting to user installation because normal site-packages is not writeable
Collecting pybluez
  Using cached PyBluez-0.23.tar.gz (97 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pybluez
  Building wheel for pybluez (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [27 lines of output]
      /home/kaustubhpawar/.local/lib/python3.11/site-packages/setuptools/_distutils/dist.py:275: UserWarning: Unknown distribution option: 'use_2to3'
        warnings.warn(msg)
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.11
      creating build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/msbt.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/bluez.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/btcommon.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/macos.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/__init__.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/widcomm.py -> build/lib.linux-x86_64-3.11/bluetooth
      copying bluetooth/ble.py -> build/lib.linux-x86_64-3.11/bluetooth
      running build_ext
      creating build/temp.linux-x86_64-3.11
      creating build/temp.linux-x86_64-3.11/bluez
      x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -g -fwrapv -O2 -fPIC -I./port3 -I/usr/include/python3.11 -c bluez/btmodule.c -o build/temp.linux-x86_64-3.11/bluez/btmodule.o
      bluez/btmodule.c: In function ‘PyInit__bluetooth’:
      bluez/btmodule.c:2978:25: error: lvalue required as left operand of assignment
       2978 |     Py_TYPE(&sock_type) = &PyType_Type;
            |                         ^
      bluez/btmodule.c:2979:32: error: lvalue required as left operand of assignment
       2979 |     Py_TYPE(&sdp_session_type) = &PyType_Type;
            |                                ^
      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 pybluez
  Running setup.py clean for pybluez
Failed to build pybluez
ERROR: Could not build wheels for pybluez, which is required to install pyproject.toml-based projects
1

There are 1 best solutions below

3
Corralien On

You need to install some dev libraries to build the python package. If you are on Debian or Ubuntu, you have to install libbluetooth-dev:

[...]$ sudo apt install libbluetooth-dev

Then try to install pybluez again.

More information on GitHub