Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bleak Version is not supporting in the win11 #1596

Open
Asahi-139 opened this issue Jun 11, 2024 · 11 comments
Open

Bleak Version is not supporting in the win11 #1596

Asahi-139 opened this issue Jun 11, 2024 · 11 comments
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend more info required Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback

Comments

@Asahi-139
Copy link

  • bleak version: 0.22.2
  • Python version: 3.12
  • Operating System: Windows 11
  • BlueZ version (bluetoothctl -v) in case of Linux:

I am making a GUI which communicates with BLE device and do some work.
my bleak module and everything was working fine in the win10. but as soon as i shifted to the win11. i am getting some error whenever i run my exe file. i have tried the same script on win 10 then it is working fine.

i think bleak module doesn't support the win 11 till now. then can anyone help me to work around it as in my company i am not allowed to use win 10.

i have tried installling the winrt and all but nothing seems to work.

image

@Asahi-139 Asahi-139 changed the title Bleak Version in not supporting in the win11 Bleak Version is not supporting in the win11 Jun 11, 2024
@dlech
Copy link
Collaborator

dlech commented Jun 11, 2024

It sounds like Bleak didn't get installed correctly on Windows 11. The required packages for Python 3.12 on Windows can be found in the pyproject.toml file.

bleak/pyproject.toml

Lines 32 to 39 in ce48c7f

"winrt-runtime" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Devices.Bluetooth" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Devices.Bluetooth.Advertisement" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Devices.Bluetooth.GenericAttributeProfile" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Devices.Enumeration" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Foundation" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Foundation.Collections" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }
"winrt-Windows.Storage.Streams" = { version = "^2", markers = "platform_system=='Windows'", python = ">=3.12" }

@dlech
Copy link
Collaborator

dlech commented Jun 11, 2024

If you are running Bleak from the source directory, you can install everything using poetry install and then run things with poetry run python ... or use poetry shell so you don't have to write poetry run every time.

@dlech dlech added the Backend: WinRT Issues or PRs relating to the WinRT backend label Jun 11, 2024
@Asahi-139
Copy link
Author

Asahi-139 commented Jun 12, 2024 via email

@dlech
Copy link
Collaborator

dlech commented Jun 12, 2024

It's not really clear what you did or what you are trying to do, so hard to help without more information. Are you using a virtual environment, etc.?

@lmbeauplet
Copy link

lmbeauplet commented Jun 19, 2024

Hi, this issue seems to be not related only on Win11 but also in Win10. So maybe related to python 3.12 on Windows. I did the test today with a bleak desktop application packaged with pyinstaller with my package for python3.10 and python3.12 and with python3.12 i have the same error.

@dlech
Copy link
Collaborator

dlech commented Jun 19, 2024

Can you give the exact steps needed to reproduce the error?

@dlech dlech added the more info required Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback label Jun 19, 2024
@lmbeauplet
Copy link

lmbeauplet commented Jun 20, 2024

I use poetry as package manager, so firstly I bumped my python version from 3.10 to 3.12 with the set of line python = ">3.11,<3.13" in pyproject.toml (bleak version in 0.22.2)

Then in my release GitHub action workflow:

  • I set up runner windows latest (10)
  • I set up python 3.12 (3.12.2) x64
  • Run poetry update --no-interaction
  • I package my app with pyinstaller
  • I run it, when i try to scan device, this error appear in loop
msg=Received %s.
  File "bleak\backends\winrt\scanner.py", line 147, in _received_handler
Exception in callback BleakScannerWinRT._received_handler(<winrt._winrt...00265D2983270>, <winrt._winrt...00265D2983290>)
Traceback (most recent call last):
ModuleNotFoundError: No module named 'winrt.windows.foundation.collections'

@dlech
Copy link
Collaborator

dlech commented Jun 20, 2024

Did you try https://pyinstaller.org/en/stable/when-things-go-wrong.html#listing-hidden-imports to see if you can help pyinstaller find the missing packages?

@lmbeauplet
Copy link

Hi ! I bumped my python version to 3.12 and tried a workaround for pyinstaller in adding this code to my builder script:

"--hidden-import 'winrt.windows.foundation.collections' "
"--collect-all winrt "

And it works, the .exe build is functional. So this thing doesn't explain the bug related to this issue but this allows to build .exe application with a workaround.

@lmbeauplet
Copy link

lmbeauplet commented Jun 24, 2024

Also, to avoid to get looped line Received %s. when a bug occurs, maybe it will be good to replace line

logger.debug("Received %s.", _format_event_args(event_args))

by

logger.debug("Received %s." % _format_event_args(event_args))

or

logger.debug(f"Received {_format_event_args(event_args)}")

change comma by percent to get string arg and so get the formatted value from function _format_event_args
in file /bleak/backends/winrt class BleakScannerWinRT._received_handler l.117

@dlech
Copy link
Collaborator

dlech commented Jun 24, 2024

An even better fix would be to avoid calling _format_event_args at all if the log level is not debug.

if logger.isEnabledFor(logging.DEBUG):
    logger.debug("Received %s.", _format_event_args(event_args))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend more info required Issues does not have a reproducible test case, has insufficent logs or otherwise needs more feedback
Projects
None yet
Development

No branches or pull requests

3 participants