龙空技术网

pyinstaller 打包oracle脚本

宇宙小灵通173 143

前言:

今天看官们对“python封装oracle”大致比较关注,小伙伴们都需要知道一些“python封装oracle”的相关资讯。那么小编在网摘上搜集了一些有关“python封装oracle””的相关文章,希望你们能喜欢,姐妹们一起来了解一下吧!

1、准备

pip install cx_Oracle

oracle官网下载instantclient_11_2并安装

cd /home/oracle/so/libcp /opt/instantclient_11_2/libclntsh.so ./cp /opt/instantclient_11_2/libnnz11.so ./cp /opt/instantclient_11_2/libocci.so ./cp /opt/instantclient_11_2/libociicus.so ./cp /opt/instantclient_11_2/libocijdbc11.so ./
2、测试程序

vi /home/oracle/so/test/test.py 内容如下:

import cx_Oracleconn = cx_Oracle.connect('system/oracle@192.168.0.13/ORCL')  cursor = conn.cursor ()cursor.execute ("select * from tab")row = cursor.fetchone ()print rowcursor.close ()conn.close ()
3、spec文件

在myapp目录下创建test.spec文件,内容如下:

# -*- mode: python -*-block_cipher = Nonea = Analysis(['test.py'],             pathex=['/home/oracle/so/test','/home/oracle/so/lib'],             ###################################################             binaries=[ \             ('../lib/libclntsh.so.11.1','.'), \             ('../lib/libnnz11.so','.'), \             ('../lib/libocci.so.11.1','.'), \             ('../lib/libociei.so','.'), \             ('../lib/libocijdbc11.so','.') \              ],             ###################################################             datas=[],             hiddenimports=[],             hookspath=[],             runtime_hooks=[],             excludes=[],             win_no_prefer_redirects=False,             win_private_assemblies=False,             cipher=block_cipher)pyz = PYZ(a.pure, a.zipped_data,             cipher=block_cipher)exe = EXE(pyz,          a.scripts,          a.binaries,          a.zipfiles,          a.datas,          name='test',          debug=False,          strip=False,          upx=True,          console=True )
4、打包可执行文件

打包运行pyinstaller命令,如下:

pyinstaller run.spec

打包后在dist目录下生成test的可执行文件。

标签: #python封装oracle