python – module ‘socket’ has no attribute ‘BTPROTO_RFCOMM’ on pop os with pyenv

I’m trying bluetooth probramming with Python on linux.

After installing pybluez2, when I try importing the bluetooth module

improt bluetooth

I get the following error:

>>> import bluetooth
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gerardozinno/.pyenv/versions/3.10.1/lib/python3.10/site-packages/bluetooth/", line 22, in <module>
    from bluetooth.native_socket import BluetoothSocket
  File "/home/gerardozinno/.pyenv/versions/3.10.1/lib/python3.10/site-packages/bluetooth/", line 7, in <module>
    Protocols.RFCOMM: socket.BTPROTO_RFCOMM
AttributeError: module 'socket' has no attribute 'BTPROTO_RFCOMM'

Looking up on google I found this github issue stating that the problem is my Python binary, which is lacking bluetooth support:

Your python binary was built without Bluetooth support. You can install python from another repository that supports Bluetooth or compile it yourself. Make sure you have all the bluetooth libraries installed on your distro before compiling it.

How can I have a version of python with bluetooth support on my machine possibly without having to compile python myself?

To manage all my python versions and environments I use pyenv.

Is there a way to install a a version of Python with bluetooth support using pyenv?

Read more here: Source link