一、安装dmPython
对于达梦数据库,必须首先安装dmPython,才可以使用,在$DM_HOME/drivers 目录下有多种类型的驱动:
[dmdba@dm8 ~]$ cd /dm/dmdbms/drivers/
[dmdba@dm8 drivers]$ ls
dci dotNet dpi fldr go jdbc logmnr msgparse odbc php_pdo python r2dbc
[dmdba@dm8 drivers]$ cd python/
[dmdba@dm8 python]$ ls
django_dmPython2.0.0 django_dmPython3.0.0 dmPython sqlalchemy sqlalchemy1.4.6 sqlalchemy2.0.0
[dmdba@dm8 python]$ cd dmPython/
[dmdba@dm8 dmPython]$ ls
Buffer.c Connection.c Environment.c Error.h exLob.c py_Dameng.c README.txt row.h strct.h trc.c var.c vBfile.c vDateTime.c vLob.c vNumber.c vString.c Buffer.h Cursor.c Error.c exBfile.c exObject.c py_Dameng.h row.c setup.py tObject.c trc.h var_pub.h vCursor.c vInterval.c vlong.c vObject.c
这里我们需要手工安装dmPython 包。进入dmPython目录后执行命令:
python setup.py install
命令虽简单,但过程插曲比较多。
1、插曲一:权限问题Permission denied
开始使用dmdba 用户执行,报如下错误:
[dmdba@dm8 dmPython]$ python setup.py install
running install
error: can't create or remove files in install directory
[dmdba@dm8 dmPython]$ su
# 输入root密码
[root@dm8 ~]#
2、 插曲二: cannot locate an Dameng software installation
切换成root用户执行,又报如下错误:
[root@dm8 ~]# cd /dm/dmdbms/drivers/python/dmPython
[root@dm8 dmPython]# python setup.py install
Traceback (most recent call last):
File "setup.py", line 103, in <module>
raise DistutilsSetupError("cannot locate an Dameng software " /
distutils.errors.DistutilsSetupError: cannot locate an Dameng software installation
[root@dm8 dmPython]#
因为安装依赖DM的环境,这里在root用户下配置dm的环境变量
[root@dm8 dmPython]# cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export PATH="/dm/dmdbms/bin:$PATH"
export DM_HOME="/dm/dmdbms"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/dm/dmdbms/bin"
[root@dm8 dmPython]# source ~/.bash_profile
3 、插曲三:unable to execute gcc: No such file or directory
解决上面的问题后继续安装:
[root@dm8 dmPython]# python setup.py install
running install
……
building 'dmPython' extension
creating build
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DDM64 -I/dm/dmdbms/include -I/usr/include/python2.7 -c py_Dameng.c -o build/temp.linux-x86_64-2.7/py_Dameng.o -DBUILD_VERSION=2.3
unable to execute gcc: No such file or directory
error: command 'gcc' failed with exit status 1
[root@dm8 dmPython]#
# 提示缺少gcc 包,直接yum 安装:
[root@dm8 dmPython]# yum install gcc* -y
4、插曲四:py_Dameng.h:8:20: fatal error: Python.h: No such file or directory
解决gcc 包之后继续安装:
[root@dm8 dmPython]# python setup.py install
running install
……
building 'dmPython' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DDM64 -I/dm/dmdbms/include -I/usr/include/python2.7 -c py_Dameng.c -o build/temp.linux-x86_64-2.7/py_Dameng.o -DBUILD_VERSION=2.3
In file included from py_Dameng.c:3:0:
py_Dameng.h:8:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
[root@dm8 dmPython]#
# 这里是缺少python-devel 包,老方法,直接yum 解决:
[root@dm8 dmPython]# yum install python-devel
最后终于安装成功:
[root@dm8 dmPython]# python setup.py install
……
creating dist
creating 'dist/dmPython-2.3-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing dmPython-2.3-py2.7-linux-x86_64.egg
Copying dmPython-2.3-py2.7-linux-x86_64.egg to /usr/lib64/python2.7/site-packages
Adding dmPython 2.3 to easy-install.pth file
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
[root@dm8 dmPython]#
二、测试dmPython
[root@dm8 dmPython]# python
Python 2.7.5 (default, Feb 20 2018, 09:19:12)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
# 测试代码(更换成自己的达梦配置)
>>>
import dmPython
conn=dmPython.connect(user='SYSDBA',password='SYSDBA',server= '192.168.201.118',port=5236)
cursor = conn.cursor()
cursor.execute('select username from dba_users')
values = cursor.fetchall()
print(values)
cursor.close()
conn.close()
输出数据库中的用户名则表示连接数据库成功。
https://eco.dameng.com/document/dm/zh-cn/start/python-development.html
标签:python,安装,py,install,dm8,root,dmPython From: https://www.cnblogs.com/DQ-MINE/p/17995251