0
点赞
收藏
分享

微信扫一扫

Python操作oracle并打包成exe文件

孟佳 2022-02-07 阅读 81

尝试学习用python查询oracle数据库,并打成exe可执行文件,希望在没装python的环境下也可以运行。

电脑环境

win7 64位

python 3.6 32 位

oracle ....

1、安装cx_oracle

我当时直接用pip install cx_Oracle 安装成功,后来看资料说安装的版本要与python和oracle对应​​https://www.cnblogs.com/lansan0701/p/8039332.html​​

Python安装目录Python\Python36-32\Lib\site-packages下有cx_Oracle.cp36-win32.pyd和cx_Oracle-5.3-py3.6.egg-info目录

2、oracle访问户端

3、代码

#!/usr/bin/python3
# -*- coding:utf-8 -*-

import cx_Oracle

if __name__ == '__main__':
try:
db=cx_Oracle.connect('user/pw@ip/sid')

cr=db.cursor() #create cursor
sql='xxxx'
cr.execute(sql)
rs=cr.fetchall()
for x in rs:
print(x)


cr.close()
db.close()


input('Please press enter key to exit ...')

except Exception as e:
print('My exception occurred, value:', e)
input('Please press enter key to exit ...')

4、打包

尝试用pyinstall打包,打包后执行一直提示Unable to acquire Oracle environment handle,换用cx_freeze打包

安装cx_freeze:

pip install cx_freeze

运行cxfreeze -h正常

打包命令:cxfreeze hello.py --target-dir dist

网上有遇到失败的

​​https://www.cnblogs.com/gexbooks/p/11270206.html​​​​

​​https://blog.csdn.net/qq_37193537/article/details/81135178​​​​

5、打包后执行dist中的exe还是提示ORA-24315: illegal attribute type

参考​​https://www.cnblogs.com/apff/p/11087304.html​​

因为在pycharm中运行正常,所以我将Python\Python36-32\Lib\site-packages目录下的oci.dll,oraocci11.dll,oraociei11.dll拷贝到disk/lib中,再执行exe文件运行正常

举报

相关推荐

0 条评论