温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

pyinstaller打包cx_Oracle库会遇到什么问题

发布时间:2021-11-18 15:37:22 来源:亿速云 阅读:480 作者:小新 栏目:编程语言

这篇文章主要介绍pyinstaller打包cx_Oracle库会遇到什么问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

pyinstaller打包cx_Oracle库问题处理记录

1.下载cx_Oracle

在windows下不要使用easy_install或者pip,因为这样安装不会同步环境,并报错:

distutils.errors.DistutilsSetupError: cannot locate Oracle include files in...

因此下载cx_Oracle5.3.exe文件安装

https://files.pythonhosted.org/packages/48/83/15dd03c752d8840ce763bfad5ebd02568f16b2d6709a2b7e6ff97bc3c0f3/cx_Oracle-5.3-11g.win-amd64-py2.7.exe

2. 下载Oracle Instant Client或使用完整的数据库客户端安装包,版本需11.2以上。

数据库客户端版本和python版本及位数需一致。

下载地址:

64位:https://www.oracle.com/technetwork/topics/winx64soft-089540.html

32位:http://www.oracle.com/technetwork/topics/winsoft-085727.html

下载后解压到某一路径,并将该路径添加到系统的环境变量,命名为ORACLE_HOME,将ORACLE_HOME添加到path下,否则会报错

cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

该目录下可自建network\admin文件夹,存放tnsnames.ora, sqlnet.ora or oraaccess.xml文件

3.安装VC环境

Oracle Instant Client libraries需要VC环境,并匹配对应的位数和版本,对应关系如下:

For Instant Client 18 or 12.2 install VS 2013

For Instant Client 12.1 install VS 2010

For Instant Client 11.2 install VS 2005 64-bit or VS 2005 32-bit

4.解决中文乱码问题

4.1设置环境变量(全局,可能对其它Oracle客户端产生影响)

“计算机”->“系统属性”->“高级系统设置”->“系统属性/高级 选项卡”->“环境变量”->“系统变量”->“新建”->

变量名:NLS_LANG

变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK

4.2 python环境下设置

import os  

os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'  

#或者os.environ['NLS_LANG'] = 'AMERICAN_AMERICA.AL32UTF8'

5.连接数据库

import cx_Oracle  

db=cx_Oracle.connect('system/oracle@10.98.156.148/oral')

cursor = db.cursor()

cursor.execute ("select * from dba_users where user_id=62")

row = cursor.fetchall ()

print (row[0])

db.commit()  

cursor.close ()

db.close(

如上配置后,不需要再本机上安装Oracle,也不需要新建NETWORK/ADMIN目录添加tnsnames.ora文件,更不要把oci.dll移到site-packages

6.打包后执行报错:cx_oracle_Error object at 0x000

环境:win2008r2_x64+py2.7.13_x64上

错误提示:cx_Oracle.DatabaseError: DPI-1050: Oracle Client library must be at version 11.2

解决:确认当前版本时11以上,如是,将安装路径下Lib和安装路径都添加到path变量前面。

7.win2008r2 x64 直接运行脚本无问题,运行打包程序报错.无法定位程序输入点ucrtbase.terminate 于动态链接库api-ma-win-crt-runtime-11-1-0.dll上

解决步骤:

A、打开CMD,输入 winver.exe ,回车运行,查看当前Windows版本

如果版本为7600,则首先安装:windows6.1-KB976932-X64.exe(链接),将版本升级为?7601:Service Pack 1,再进行第2步;

如果版本如上图所示,为7601:Service Pack 1,直接进行第2步;

B、安装:Microsoft .NET Framework 4.6.1 NDP461-KB3102438-Web.exe(链接);

C、安装:Visual C++ Redistributable for Visual Studio 2015 vc_redist.x64.exe(链接);

D、一般情况下,到第3步问题已经解决,但是如果再一次安装软件,还是会出错“无法定位程序输入点ucrtbase.terminate于动态链接库api-ms-win-crt-runtime-|1-1-0.dll”,那么可以安装补丁:Windows6.1-KB2999226-x64 .msu(链接);

8.错误提示:cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

如命令行执行报此错误:将instantclient目录下的所有*.dll文件拷贝到Python27\Lib\site-packages目录下,可解决问题。

如程序命令行执行无问题,命令行sqlplus直连数据库无问题,但打包后执行报错。则如下解决

网上类似情况:

https://stackoverflow.com/questions/36478831/pyinstaller-cx-oracle-interfaceerror-unable-to-acquire-oracle-environment-hand

问题的原因是pyinstall打包时没将oracle链接库打包进去,导致换个环境就报错。

先正常打包一遍,生成spec文件,如

python -F checkreport.py -i dl.ico

再编辑程序目录下checkreport.spec文件,修改a.binaries行,修改后如下。须将oraociei11.dll拷贝到本目录下

a.binaries+[('oraociei11.dll','oraociei11.dll','BINARY')],

然后重新编译一遍;

pyinstaller checkreport.spec

测试后在别机器上运行正常。

官网中关于ODBC的资料

https://www.oracle.com/technetwork/database/features/oci/odbc-ic-releasenotes-094306.html

On Windows

Patching the Instant Client ODBC driver on Windows can be done only by manually copying the ODBC driver shared library files and supporting library files from a patched ORACLE_HOME or from an unpacked Oracle Database Bundle patch. These should be copied into the Instant Client directory. Generating an Instant Client ODBC package is not available on Windows. 

The files that must be copied to the Instant Client directory:

ODBC driver shared library files: sqora32.dll, sqoras32.dll, sqresus.dll, sqresja.dll

Required additional files when using Oracle Basic Instant Client:

For 12c: oraociei12.dll, orannzsbb12.dll, oci.dll, oraons.dll, ociw32.dll, oraociei12.sym, orannzsbb12.sym, oci.sym, ociw32.sym

For 11g: oraociei11.dll, orannzsbb11.dll, oci.dll, ociw32.dll, oraociei11.sym, orannzsbb11.sym, oci.sym, ociw32.sym

Required additional files when using Oracle Basic Light Instant Client:

For 12c: oraociicus12.dll, orannzsbb12.dll, oci.dll, oraons.dll, ociw32.dll, oraociicus12.sym, orannzsbb12.sym, oci.sym, ociw32.sym

For 11g: oraociicus11.dll, orannzsbb11.dll, oci.dll, ociw32.dll, oraociicus11.sym, orannzsbb11.sym, oci.sym, ociw32.sym

Note: While copying from the Oracle Database Bundle patch, some of the files above may be missing. This implies that those files are unchanged and do not need to be patched.

9.打包程序运行报错:UnicodeDecodeError: 'utf-8' codec can't decode byte

本机环境:win10_x64,anaconda_3 python 3.6.5_x64,cx_oracle 7

程序在命令行运行无问题,用pyinstaller打包后,本机运行无问题,在别机器运行报错,报错提示如下

C:\Users\super>D:\checkreportv1\checkreportv1\checkreportp36w10.exe

Traceback (most recent call last):

  File "checkreport.py", line 9, in <module>

  File "<frozen importlib._bootstrap>", line 971, in _find_and_load

  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

  File "d:\programdata\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

  File "oradb.py", line 4, in <module>

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 53: invalid start byte [6380] Failed to execute script checkreport

网搜,同类情况

https://ask.csdn.net/questions/647140?sort=votes_count

使用Pyinstaller打包含有cx_Oracle模块遇到的问题

该问题暂没找到解决办法。找了一个win2008r2_x64+py2.7.13_x64+cx_Oracle_5.13环境,打包后转发系统执行正常。

以上是“pyinstaller打包cx_Oracle库会遇到什么问题”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI