diff --git a/CHANGELOG.md b/CHANGELOG.md index 18d364c..d6cbc3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use relative paths when compiling multi-file projects. +### Fixed +- Fixed `pybricksdev` BLE commands not working on Windows when `pythoncom` + package is present in environment. + ## [1.0.0-alpha.48] - 2024-05-04 ### Changed diff --git a/pybricksdev/cli/__init__.py b/pybricksdev/cli/__init__.py index 56c3ea6..5fb9df5 100644 --- a/pybricksdev/cli/__init__.py +++ b/pybricksdev/cli/__init__.py @@ -343,6 +343,15 @@ async def run(self, args: argparse.Namespace): def main(): """Runs ``pybricksdev`` command line interface.""" + if sys.platform == "win32": + # Hack around bad side-effects of pythoncom on Windows + try: + from bleak_winrt._winrt import MTA, init_apartment + except ImportError: + from winrt._winrt import MTA, init_apartment + + init_apartment(MTA) + # Provide main description and help. parser = argparse.ArgumentParser( prog=PROG_NAME,