带pip问题的Gattlib安装

2024-06-24 12:20:40 发布

您现在位置:Python中文网/ 问答频道 /正文

最近,我一直在尝试使用pip将gattlib安装到python中,如下所示:

sudo -H python -m pip install gattlib

但结果就是这个错误:

Collecting gattlib
  Using cached gattlib-0.20201113.tar.gz (50 kB)
Building wheels for collected packages: gattlib
  Building wheel for gattlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-TyrlK8/gattlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-TyrlK8/gattlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-fEQmhc
       cwd: /tmp/pip-install-TyrlK8/gattlib/
  Complete output (46 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'gattlib' extension
  creating build
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/src
  creating build/temp.linux-x86_64-2.7/src/bluez
  creating build/temp.linux-x86_64-2.7/src/bluez/lib
  creating build/temp.linux-x86_64-2.7/src/bluez/attrib
  creating build/temp.linux-x86_64-2.7/src/bluez/src
  creating build/temp.linux-x86_64-2.7/src/bluez/src/shared
  creating build/temp.linux-x86_64-2.7/src/bluez/btio
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-QDqKfA/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVERSION="5.25" -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Isrc/bluez -I/usr/include/python2.7 -c src/gattservices.cpp -o build/temp.linux-x86_64-2.7/src/gattservices.o
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-QDqKfA/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVERSION="5.25" -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Isrc/bluez -I/usr/include/python2.7 -c src/beacon.cpp -o build/temp.linux-x86_64-2.7/src/beacon.o
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-QDqKfA/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DVERSION="5.25" -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Isrc/bluez -I/usr/include/python2.7 -c src/bindings.cpp -o build/temp.linux-x86_64-2.7/src/bindings.o
  src/bindings.cpp: In function ‘PyObject* createExceptionClass(const char*, PyObject*, boost::python::api::object&, const char*)’:
  src/bindings.cpp:199:57: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
    199 |     PyObject* rv = PyErr_NewExceptionWithDoc(qname.c_str(), docstr, baseType, 0);
        |                                              ~~~~~~~~~~~^~
        |                                                         |
        |                                                         const char*
  In file included from /usr/include/python2.7/Python.h:124,
                   from /usr/include/boost/python/detail/wrap_python.hpp:178,
                   from /usr/include/boost/python/detail/prefix.hpp:13,
                   from /usr/include/boost/python/args.hpp:8,
                   from /usr/include/boost/python.hpp:11,
                   from src/bindings.cpp:6:
  /usr/include/python2.7/pyerrors.h:227:11: note:   initializing argument 1 of ‘PyObject* PyErr_NewExceptionWithDoc(char*, char*, PyObject*, PyObject*)’
    227 |     char *name, char *doc, PyObject *base, PyObject *dict);
        |     ~~~~~~^~~~
  src/bindings.cpp:199:61: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
    199 |     PyObject* rv = PyErr_NewExceptionWithDoc(qname.c_str(), docstr, baseType, 0);
        |                                                             ^~~~~~
        |                                                             |
        |                                                             const char*
  In file included from /usr/include/python2.7/Python.h:124,
                   from /usr/include/boost/python/detail/wrap_python.hpp:178,
                   from /usr/include/boost/python/detail/prefix.hpp:13,
                   from /usr/include/boost/python/args.hpp:8,
                   from /usr/include/boost/python.hpp:11,
                   from src/bindings.cpp:6:
  /usr/include/python2.7/pyerrors.h:227:23: note:   initializing argument 2 of ‘PyObject* PyErr_NewExceptionWithDoc(char*, char*, PyObject*, PyObject*)’
    227 |     char *name, char *doc, PyObject *base, PyObject *dict);
        |                 ~~~~~~^~~
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for gattlib

我的目标是使用我的PC机的内置BLE模块,通过pybluez库通过python进行通信。我使用的是Python的旧版本,因为我想要使用它的脚本是用Python 2.7编写的。到目前为止,我能够使用以下命令在Python 3.8中安装gattlib库:

sudo -H python3 -m pip install gattlib

我已经在Python2.7和Python3.8中安装了pybluez库,当我用耳机测试它时,它似乎可以工作。另外,gattlib库似乎在python3.8中工作,因为我能够用它检测ESP32 BLE服务器,但在python2.7中它不工作,因为gattlib库丢失了。 Python3.8在尝试使用BLE时也需要sudo权限,您知道如何避免这种情况吗

测试时,我使用了以下pybluez测试示例:

# simple inquiry example
import bluetooth

nearby_devices = bluetooth.discover_devices(lookup_names=True)
print("Found {} devices.".format(len(nearby_devices)))

for addr, name in nearby_devices:
    print("  {} - {}".format(addr, name))

BLE:

# bluetooth low energy scan
from bluetooth.ble import DiscoveryService

service = DiscoveryService()
devices = service.discover(2)

for address, name in devices.items():
    print("name: {}, address: {}".format(name, address))

你知道如何解决安装错误吗? 提前谢谢


Tags: frombuildcreatingsrcincludelinuxusrtemp