前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux (Centos) Python compile and install Dameng driver dmPython

Linux (Centos) Python compile and install Dameng driver dmPython

作者头像
码农笔录
发布2021-12-06 19:07:17
5820
发布2021-12-06 19:07:17
举报
文章被收录于专栏:码农笔录码农笔录

原文链接 https://www.aiprose.com/blog/151 点击访问

dmPython is a database access interface developed by DM based on the API usage regulations in Python DB API version 2.0.

You need to install dmPython when using Python to connect to the Dameng database. After installing the DM database software, you can find the driver source code of dmPython in the drivers directory under the installation path. Since the source code is provided, you need to compile and install it yourself.

When installing, distinguish whether the machine has already installed the Dameng database. If the machine has already installed the Dameng database, refer to the first type. If the machine is not installed, please refer to the second one.

Linux platform installation method one

Note: DM database needs to be installed first

1.Download the driver package source code

代码语言:javascript
复制
wget https://download.dameng.com/eco/docs/python-126594-20201027.zip

or

curl https://download.dameng.com/eco/docs/python-126594-20201027.zip -o python-126594-20201027.zip

2.Unzip the driver package

代码语言:javascript
复制
unzip python-126594-20201027.zip

3.Compile the driver package

代码语言:javascript
复制
//cd your Driver source code decompression directory 
cd python/dmPython_C/dmPython

python setup.py install

Linux platform installation method two

Note: There is no DM database installed on this machine

1.Download the driver package source code

代码语言:javascript
复制
wget https://download.dameng.com/eco/docs/python-126594-20201027.zip
 or
curl https://download.dameng.com/eco/docs/python-126594-20201027.zip -o python-126594-20201027.zip

2.Unzip the driver package

代码语言:javascript
复制
unzip python-126594-20201027.zip

3.Install gcc

Compilation and installation must be GCC, if not installed, please install it first

代码语言:javascript
复制
yum install gcc

4.Set environment variables

Set the DM_HOME environment variable to a certain directory, assuming it is: /data/publish/python/dmdbms

Note: dmPython completes the Python module extension by calling the DM DPI interface. In its use, in addition to the Python standard library, a DPI operating environment is also required.

代码语言:javascript
复制
vi /etc/profile

// Add the following configuration
export DM_HOME=/data/publish/python/dmdbms
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/publish/python/dmdbms/

source /etc/profile

If LD_LIBRARY_PATH is not set, an error will be reported:

代码语言:javascript
复制
 import dmPython
  File "build/bdist.linux-x86_64/egg/dmPython.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/dmPython.py", line 6, in __bootstrap__
ImportError: libdmdpi.so: cannot open shared object file: No such file or directory

5.Copy files // Copy from other machines with the same operating system where DM database has been installed, or download my available files Click to download dpi file

代码语言:javascript
复制
Copy all files under dmserver/drivers/dpi to /data/publish/python/dmdbms
image.png
image.png

5.Compile the dmPython

代码语言:javascript
复制
//cd your Driver source code decompression directory
cd python/dmPython_C/dmPython

python setup.py install

If an error is reported, there is no such file or directory in Python.h

dmPython compilation error.png
dmPython compilation error.png

Solution: Install the python-devel dependency package.

代码语言:javascript
复制
yum install python-devel

//python3
yum install python3-devel

Then execute

代码语言:javascript
复制
python setup.py install

The successful compilation is as shown in the figure:

代码语言:javascript
复制
Compilation result

Installed /usr/lib64/python2.7/site-packages/dmPython-2.3-py2.7-linux-x86_64.egg
Processing dependencies for dmPython==2.3
Finished processing dependencies for dmPython==2.3
image.png
image.png

You can check whether the installation is successful through pip list

image.png
image.png

Write test code

vi testdm.py

代码语言:javascript
复制
#!/usr/bin/python
#coding:utf-8
import dmPython
try:
    conn = dmPython.connect(user='SYSDBA', password='SYSDBA', server='192.168.0.122',  port=5236)
    cursor  = conn.cursor()
    print('python: conn success!')
    conn.close()
except (dmPython.Error, Exception) as err:
    print(err)

Then execute

代码语言:javascript
复制
python test.py 

If the connection is successful, it will output conn success!

image.png
image.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-10-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Linux platform installation method one
  • Linux platform installation method two
  • Write test code
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档