Linux (Centos) Python compile and install Dameng driver dmPython

内容纲要

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

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

unzip python-126594-20201027.zip

3.Compile the driver package

//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

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

unzip python-126594-20201027.zip

3.Install gcc

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

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.

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:

 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

Copy all files under dmserver/drivers/dpi to /data/publish/python/dmdbms

image.png

5.Compile the dmPython

//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

Solution: Install the python-devel dependency package.

yum install python-devel

//python3
yum install python3-devel

Then execute

python setup.py install

The successful compilation is as shown in the figure:

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

You can check whether the installation is successful through pip list

image.png

Write test code

vi testdm.py

#!/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

python test.py 

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

image.png

标签

发表评论