pyinstaller打包cx_Oracle庫會遇到什么問題

這篇文章主要介紹pyinstaller打包cx_Oracle庫會遇到什么問題,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了河?xùn)|免費建站歡迎大家使用!

pyinstaller打包cx_Oracle庫問題處理記錄

1.下載cx_Oracle

在windows下不要使用easy_install或者pip,因為這樣安裝不會同步環(huán)境,并報錯:

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或使用完整的數(shù)據(jù)庫客戶端安裝包,版本需11.2以上。

數(shù)據(jù)庫客戶端版本和python版本及位數(shù)需一致。

下載地址:

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

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

下載后解壓到某一路徑,并將該路徑添加到系統(tǒng)的環(huán)境變量,命名為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環(huán)境

Oracle Instant Client libraries需要VC環(huán)境,并匹配對應(yīng)的位數(shù)和版本,對應(yīng)關(guān)系如下:

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設(shè)置環(huán)境變量(全局,可能對其它Oracle客戶端產(chǎn)生影響)

“計算機”->“系統(tǒng)屬性”->“高級系統(tǒng)設(shè)置”->“系統(tǒng)屬性/高級 選項卡”->“環(huán)境變量”->“系統(tǒng)變量”->“新建”->

變量名:NLS_LANG

變量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK

4.2 python環(huán)境下設(shè)置

import os  

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

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

5.連接數(shù)據(jù)庫

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.打包后執(zhí)行報錯:cx_oracle_Error object at 0x000

環(huán)境: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 于動態(tài)鏈接庫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步問題已經(jīng)解決,但是如果再一次安裝軟件,還是會出錯“無法定位程序輸入點ucrtbase.terminate于動態(tài)鏈接庫api-ms-win-crt-runtime-|1-1-0.dll”,那么可以安裝補?。篧indows6.1-KB2999226-x64 .msu(鏈接);

8.錯誤提示:cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle

如命令行執(zhí)行報此錯誤:將instantclient目錄下的所有*.dll文件拷貝到Python27\Lib\site-packages目錄下,可解決問題。

如程序命令行執(zhí)行無問題,命令行sqlplus直連數(shù)據(jù)庫無問題,但打包后執(zhí)行報錯。則如下解決

網(wǎng)上類似情況:

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

問題的原因是pyinstall打包時沒將oracle鏈接庫打包進去,導(dǎo)致?lián)Q個環(huán)境就報錯。

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

python -F checkreport.py -i dl.ico

再編輯程序目錄下checkreport.spec文件,修改a.binaries行,修改后如下。須將oraociei11.dll拷貝到本目錄下

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

然后重新編譯一遍;

pyinstaller checkreport.spec

測試后在別機器上運行正常。

官網(wǎng)中關(guān)于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

本機環(huán)境: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

網(wǎng)搜,同類情況

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

使用Pyinstaller打包含有cx_Oracle模塊遇到的問題

該問題暫沒找到解決辦法。找了一個win2008r2_x64+py2.7.13_x64+cx_Oracle_5.13環(huán)境,打包后轉(zhuǎn)發(fā)系統(tǒng)執(zhí)行正常。

以上是“pyinstaller打包cx_Oracle庫會遇到什么問題”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

分享題目:pyinstaller打包cx_Oracle庫會遇到什么問題
本文網(wǎng)址:http://muchs.cn/article48/jopchp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)企業(yè)網(wǎng)站制作、用戶體驗做網(wǎng)站、網(wǎng)站改版、云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)