Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

python - How to bundle cx_oracle with Pyinstaller

My goal is to use Pyinstaller to bundle an exe file from a simple python script that uses Tkinter and cx_oracle to access a database. The python code is developed on a windows machine with Anaconda, cx_oracle package and oracle client installed. Then I need to run the exe file in many target windows machines without oracle client or Python.

I am using Python 2.7 and Pyinstaller 3.1 on the development machine.

I searched quite a while online but only found one tutorial on this: https://mail.python.org/pipermail/tutor/2014-December/103608.html

I followed the same procedure and modified the spec file as below:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['mycode.py'],
             pathex=['C:\Users\myuser\PycharmProjects\mycode'],
             binaries=None,
             datas=None,
             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 + [('oraociei11.dll','D:ProgramFilesAnaconda2oraociei11.dll','BINARY')],
          a.zipfiles,
          a.datas,
          name='mycode',
          debug=False,
          strip=False,
          upx=True,
          console=True )

the bundle worked. The code runs on the original machine with oracle client installed. But on a separate machine without oracle client, it failed to run, with the below error message:

Exception in Tkinter callback Traceback (most recent call last): File "lib-tkTkinter.py", line 1537, in call File "", line 152, in login DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "The specified module could not be found". See https://oracle.github.io/odpi/doc/installation.html#windows for help

Now I am very confused what are the required steps to safely bundle an exe from a python script with cx_oracle so that it can run on a windows machine without oracle client? Or do I "have to" install oracle client on the target machine?

I really hope to find a more detailed tutorial on bundling cx_oracle with pyinstaller than the old link I found above.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

cx_Oracle requires an Oracle client. You will need to install that on the target machine! Note the link in the error message: https://oracle.github.io/odpi/doc/installation.html#windows. It should help you out with everything you need to do to get cx_Oracle working on the target machine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...