Search code examples
pythonpython-3.xpippybluezmodulenotfounderror

ModuleNotFoundError though Python module PyBluez is installed


I am using python3 with the Thonny IDE. My programs are running on a Raspberry Pi 4B.

I tried to install PyBluez on different ways, with pip and with the built-in package installer of Thonny. Every time the installation seemed to work. When I then tried to import the module via import PyBluez I always get this error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pybluez'

But when I try to install it again I get these message, what I think mean, that it is already installed:

 Requirement already satisfied: pyserial in /usr/lib/python3/dist-packages (3.4)

And the built-in package installer of Thonny shows me this message:

Installed version: 0.23
Installed to: /home/pi/.local/lib/python3.7/site-packages

Latest stable version: 0.23
Summary: Bluetooth Python extension module
Author: Albert Huang
Homepage: http://pybluez.github.io/
PyPI page: https://pypi.org/project/PyBluez/
Requires: pyobjc-core (<6,>=3.1), pyobjc-framework-Cocoa (<6,>=3.1), gattlib (==0.20150805) ; extra == 'ble'

But I still get the error that there is no module with this name.

I also tried to install the package PySerial on the same ways, but I ran into the same problem as with PyBluez. So it might be a general problem?


Solution

  • I haven't personally worked with that module, but after looking at the GitHub documentation, I can see that the import statement that is used is import bluetooth. For example, on this page that's what they have

    import bluetooth
    import bluetooth._bluetooth as bluez
    

    Consider using a different import statement