之前TDengine不支持Mac上安装TDengine的客户端和服务端,但是最近官方已经支持了,但是需要自己下载源码编译获得客户端和服务端。
并且通过修改Python的connector源码,是可以直接在Mac上开发的,因为Python的源码其实最终也是通过调用TDengine使用c编译好的包实现对服务端的访问的
1. 当前情况
- macOS Big Sur 11.2.3
- Python 3.8.2
- Git
- java version “1.8.0_181”
2. 源码编译
下载地址 git clone https://github.com/taosdata/TDengine.git
选择合适的目录,运行以下命令
git clone https://github.com/taosdata/TDengine.git
cd TDengine
mkdir debug
cd debug
cmake .. && cmake --build .
如果出现command not found: cmake
则使用brew install cmake
安装该安装包后继续执行cmake .. && cmake --build .
3. 测试服务端
成功后,进行本地客户端和服务端的测试
# 进入前目录./debug/build/bin,启动服务端
yangliu@ylmac bin % ls
cqtest demo epoll rclient rsclient rserver taos taosd taosdemo tarbitrator tdengineTest tsim waltest
yangliu@ylmac bin % ./taosd
......
config file:/usr/local/etc/taos/taos.cfg not found, all variables are set to default
......
06/23 14:13:18.871325 04945802 MND dnode:1, from offline to online
06/23 14:13:19.365177 04945800 MND user:monitor login from 127.0.0.1, result:success
06/23 14:13:33.504789 04945800 MND user:root login from 127.0.0.1, result:success
4. 测试客户端
如上,即为成功,现在看看客户端,使用命令show databases;
进行查看
yangliu@ylmac bin % ls
cqtest demo epoll rclient rsclient rserver taos taosd taosdemo tarbitrator tdengineTest tsim waltest
yangliu@ylmac bin % ./taos
Welcome to the TDengine shell from Linux, Client Version:2.1.1.0
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
config file:/usr/local/etc/taos/taos.cfg not found, all variables are set to default
taos> show databases;
name | created_time | ntables | vgroups | replica | quorum | days | keep | cache(MB) | blocks | minrows | maxrows | wallevel | fsync | comp | cachelast | precision | update | status |
====================================================================================================================================================================================================================================================================================
log | 2021-06-11 14:54:38.097 | 4 | 1 | 1 | 1 | 10 | 30 | 1 | 3 | 100 | 4096 | 1 | 3000 | 2 | 0 | us | 0 | ready |
Query OK, 1 row(s) in set (0.001608s)
如上,都是说明能够在Mac上运行服务端和客户端
5. 使用Python开发
按照常理,都应该是pip install ...
安装依赖进行开发,但是目前TDengine还未提供对应包,因此需要自己根据提供的源码进行测试,看看能否用。
5.1 调试Python源码并修改错误
Pycharm打开目录./TDengine/src/connector/python
下的代码进行测试,目录结构如下
直接运行demo.py
进行调试,会报错。
报错信息主要如下:
OSError: dlopen(libtaos.dylib, 6): image not found
本地修改方式如下:
修改taso/cinterface.py中的第255行,修改为具体的位置
==> return ctypes.CDLL('libtaos.dylib')
改为
==> return ctypes.CDLL('/usr/local/lib/libtaos.dylib')
然后运行,就可以成功。
但是目前还不知道为什么会这样报错,按理来说是应该找到的。另外一方面也说明,python其实也是通过调用taos的客户端来实现的。
config file:/usr/local/etc/taos/taos.cfg not found, all variables are set to default
(datetime.datetime(2021, 6, 11, 14, 55, 14, 74852), 0, 'user:root login from 127.0.0.1, result:success', 'ylmac.local:6030')
(datetime.datetime(2021, 6, 11, 15, 17, 30, 413588), 0, 'user:root login from 127.0.0.1, result:success', 'ylmac.local:6030')
(datetime.datetime(2021, 6, 11, 15, 31, 1, 529935), 0, 'user:root login from 127.0.0.1, result:success', 'ylmac.local:6030')
......
这样的话,就可以在Mac上通过Python调用taos客户端运行了。
5.2 本地使用
具体如何使用呢?
那就当需要使用的时候,直接在需要的工程内pip install [本地源码目录]
引入
pip install ~/TDengine/src/connector/python/taos
...
Looking in indexes: http://pypi.douban.com/simple
Processing /TDengine/src/connector/python
DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
Using legacy 'setup.py install' for taos, since package 'wheel' is not installed.
Installing collected packages: taos
Running setup.py install for taos ... done
Successfully installed taos-2.0.11
然后import taos
就可以使用了
5.3 后续
当前是2021年6月23日,TDengine还未发布Mac下的Python可使用依赖。
可通过上述方式进行修改,本地进行使用。
但是,源码ctypes.CDLL('libtaos.dylib')
中找不到依赖包还是需要一探究竟。