如何在OSX 10.9 (Mavericks)上安装pybluez或LightBlue

5 投票
2 回答
11981 浏览
提问于 2025-04-17 21:30

我在OSX10.9上尝试安装pybluez和LightBlue这两个软件,但遇到了错误。有没有人成功在Mavericks上安装过这两个软件?

我在安装LightBlue时遇到这个错误:

    === BUILD TARGET LightAquaBlue OF PROJECT LightAquaBlue WITH CONFIGURATION Release ===

Check dependencies
error: There is no SDK with the name or path '/Users/myname/Downloads/lightblue-0.4/src/mac/LightAquaBlue/macosx10.6'

** INSTALL FAILED **


The following build commands failed:
    Check dependencies
(1 failure)

而在安装pyBluez时,我遇到这个错误:

    osx/_osxbt.c:676:5: error: unknown type name 'IOBluetoothDeviceInquiryRef'; did you mean 'IOBluetoothDeviceRef'?

    IOBluetoothDeviceInquiryRef inquiry;

    ^~~~~~~~~~~~~~~~~~~~~~~~~~~

    IOBluetoothDeviceRef

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/IOBluetooth.framework/Headers/IOBluetoothUserLib.h:34:47: note: 'IOBluetoothDeviceRef' declared here

typedef struct OpaqueIOBluetoothObjectRef *                     IOBluetoothDeviceRef;

                                                                ^

osx/_osxbt.c:688:17: error: unknown type name 'IOBluetoothDeviceInquiryRef'; did you mean 'IOBluetoothDeviceRef'?

                IOBluetoothDeviceInquiryRef inquiryRef,

                ^~~~~~~~~~~~~~~~~~~~~~~~~~~

                IOBluetoothDeviceRef

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/IOBluetooth.framework/Headers/IOBluetoothUserLib.h:34:47: note: 'IOBluetoothDeviceRef' declared here

typedef struct OpaqueIOBluetoothObjectRef *                     IOBluetoothDeviceRef;

                                                                ^

osx/_osxbt.c:703:19: warning: implicit declaration of function 'IOBluetoothDeviceInquiryCreateWithCallbackRefCon' is invalid in C99 [-Wimplicit-function-declaration]

    dd->inquiry = IOBluetoothDeviceInquiryCreateWithCallbackRefCon (&dd);

                  ^

osx/_osxbt.c:703:17: warning: incompatible integer to pointer conversion assigning to 'IOBluetoothDeviceRef' (aka 'struct OpaqueIOBluetoothObjectRef *') from 'int' [-Wint-conversion]

    dd->inquiry = IOBluetoothDeviceInquiryCreateWithCallbackRefCon (&dd);

                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

osx/_osxbt.c:705:5: warning: implicit declaration of function 'IOBluetoothDeviceInquirySetCompleteCallback' is invalid in C99 [-Wimplicit-function-declaration]

    IOBluetoothDeviceInquirySetCompleteCallback (dd->inquiry,

    ^

osx/_osxbt.c:717:5: warning: implicit declaration of function 'IOBluetoothDeviceInquiryStart' is invalid in C99 [-Wimplicit-function-declaration]

    IOBluetoothDeviceInquiryStart (dd->inquiry);

    ^

osx/_osxbt.c:721:5: warning: implicit declaration of function 'IOBluetoothDeviceInquiryDelete' is invalid in C99 [-Wimplicit-function-declaration]

    IOBluetoothDeviceInquiryDelete (dd->inquiry);

    ^

5 warnings and 2 errors generated.

error: command 'gcc' failed with exit status 1

2 个回答

4

还有一个特别为 mac osx 10.8 设计的版本,链接在这里:https://github.com/0-1-0/lightblue-0.4。我也可以在 osx 10.10 Yosemite 上运行这个版本。

我只需要在 setup.py 文件中修改以下这一行:

os.system("xcodebuild install -arch 'x86_64' -target LightAquaBlue -configuration Release DSTROOT=/ INSTALL_PATH=/Library/Frameworks DEPLOYMENT_LOCATION=YES")

然后我在 /Library/Python/2.7/site-packages/lightblue/_lightblue.py 文件中插入了以下两个方法:

def deviceInquiryDeviceNameUpdated_device_devicesRemaining_(self, sender, device, devicesRemaining):

pass

def deviceInquiryUpdatingDeviceNamesStarted_devicesRemaining_(self, sender, devicesRemaining):

pass

这些方法是在构造函数之后添加的:

_AsyncDeviceInquiry(Foundation.NSObject):

完整的代码如下:

class _AsyncDeviceInquiry(Foundation.NSObject): 

# NSObject init, not python __init__
def init(self):
    try:
        attr = _IOBluetooth.IOBluetoothDeviceInquiry
    except AttributeError:
        raise ImportError("Cannot find IOBluetoothDeviceInquiry class " +\
            "to perform device discovery. This class was introduced in " +\
            "Mac OS X 10.4, are you running an earlier version?")

    self = super(_AsyncDeviceInquiry, self).init()
    self._inquiry = \
        _IOBluetooth.IOBluetoothDeviceInquiry.inquiryWithDelegate_(self)

    # callbacks
    self.cb_started = None
    self.cb_completed = None
    self.cb_founddevice = None

    return self

def deviceInquiryDeviceNameUpdated_device_devicesRemaining_(self, sender, device, devicesRemaining):
    pass

def deviceInquiryUpdatingDeviceNamesStarted_devicesRemaining_(self, sender, devicesRemaining):
    pass

最后一步是在同一个文件中修改这一行:

deviceInquiryComplete_error_aborted_, signature="v@:@iB")

改成

deviceInquiryComplete_error_aborted_, signature="v@:@iZ")

对我来说,这样运行得很好!

希望这篇帖子对你有帮助。

7

PyBluez 只适用于 Windows:

"PyBluez 可以在 GNU/Linux 和 Windows XP 上运行(支持 Microsoft 和 Widcomm 的蓝牙协议)。" - pybluez 首页

看起来你安装的是错误版本的 LightBlue

Check dependencies 
error: There is no SDK with the name or path '/Users/myname/Downloads/lightblue-0.4/src/mac/LightAquaBlue/macosx10.6'

它在寻找一个适用于 OSX 10.6 的文件。

下载并安装主版本: https://github.com/postskolkovo/lightblue-0.4

如果你遇到这个错误:

Check dependencies
No architectures to compile for (ARCHS=$(NATIVE_ARCH_ACTUAL), VALID_ARCHS=i386 x86_64).

** INSTALL FAILED **

你需要打开 setup.py 文件并更改:

os.system("xcodebuild install -arch '$(NATIVE_ARCH_ACTUAL)' -target LightAquaBlue -configuration Release DSTROOT=/ INSTALL_PATH=/Library/Frameworks DEPLOYMENT_LOCATION=YES")

为:

os.system("xcodebuild install -arch 'i386' -target LightAquaBlue -configuration Release DSTROOT=/ INSTALL_PATH=/Library/Frameworks DEPLOYMENT_LOCATION=YES")

可以通过 这个讨论找到解决方案

补充
我在 Mavericks 系统上尝试导入时,实际上遇到了 ImportError: Bundle could not be loaded 的错误。
这似乎是针对 64 位电脑的解决办法:

os.system("xcodebuild install -arch 'x86_64' -target LightAquaBlue -configuration Release DSTROOT=/ INSTALL_PATH=/Library/Frameworks DEPLOYMENT_LOCATION=YES")

如果你遇到同样的问题,可能需要这个解决方案。

撰写回答