python – 从py2exe’d程序连接到Oracle时出错:无法获取Oracle
发布时间:2020-12-16 23:31:57 所属栏目:Python 来源:网络整理
导读:当我使用 Python解释器运行它时,我的python程序(Python 2.6)工作正常,它连接到Oracle数据库(10g XE)而没有错误.但是,当我使用py2exe编译它时,可执行版本在调用cx_Oracle.connect()时失败并显示“无法获取Oracle环境句柄”. 我没有高兴地试过以下事情: Oracl
当我使用
Python解释器运行它时,我的python程序(Python 2.6)工作正常,它连接到Oracle数据库(10g XE)而没有错误.但是,当我使用py2exe编译它时,可执行版本在调用cx_Oracle.connect()时失败并显示“无法获取Oracle环境句柄”.
我没有高兴地试过以下事情: > Oracle即时客户端10g和11g 我的测试用例: testora.py: import cx_Oracle import decimal # needed for py2exe to compile this correctly def testora(): """testora >>> testora.testora() <cx_Oracle.Connection to scott@localhost:1521/orcl> X """ orcl = cx_Oracle.connect('scott/tiger@localhost:1521/orcl') print orcl curs = orcl.cursor() result = curs.execute('SELECT * FROM DUAL') for (dummy,) in result: print dummy if __name__ == '__main__': testora() build_testora.py: from distutils.core import setup import py2exe,sys sys.argv.append('py2exe') setup( options = {'py2exe': { 'bundle_files': 2,'compressed': True }},console = [{'script': "testora.py"}],zipfile = None ) 结果: C:Python26working>python testora.py <cx_Oracle.Connection to scott@localhost:1521/orcl> X C:Python26working>python build_testora.py py2exe C:Python26libsite-packagespy2exebuild_exe.py:16: DeprecationWarning: the se ts module is deprecated import sets running py2exe creating C:Python26workingbuild creating C:Python26workingbuildbdist.win32 creating C:Python26workingbuildbdist.win32winexe creating C:Python26workingbuildbdist.win32winexecollect-2.6 creating C:Python26workingbuildbdist.win32winexebundle-2.6 creating C:Python26workingbuildbdist.win32winexetemp *** searching for required modules *** *** parsing results *** *** finding dlls needed *** *** create binaries *** *** byte compile python files *** byte-compiling C:Python26libStringIO.py to StringIO.pyc byte-compiling C:Python26libUserDict.py to UserDict.pyc byte-compiling C:Python26lib__future__.py to __future__.pyc byte-compiling C:Python26lib_abcoll.py to _abcoll.pyc byte-compiling C:Python26lib_strptime.py to _strptime.pyc byte-compiling C:Python26lib_threading_local.py to _threading_local.pyc byte-compiling C:Python26libabc.py to abc.pyc byte-compiling C:Python26libatexit.py to atexit.pyc byte-compiling C:Python26libbase64.py to base64.pyc byte-compiling C:Python26libbdb.py to bdb.pyc byte-compiling C:Python26libbisect.py to bisect.pyc byte-compiling C:Python26libcalendar.py to calendar.pyc byte-compiling C:Python26libcmd.py to cmd.pyc byte-compiling C:Python26libcodecs.py to codecs.pyc byte-compiling C:Python26libcollections.py to collections.pyc byte-compiling C:Python26libcopy.py to copy.pyc byte-compiling C:Python26libcopy_reg.py to copy_reg.pyc byte-compiling C:Python26libdecimal.py to decimal.pyc byte-compiling C:Python26libdifflib.py to difflib.pyc byte-compiling C:Python26libdis.py to dis.pyc byte-compiling C:Python26libdoctest.py to doctest.pyc byte-compiling C:Python26libdummy_thread.py to dummy_thread.pyc byte-compiling C:Python26libencodings__init__.py to encodings__init__.pyc creating C:Python26workingbuildbdist.win32winexecollect-2.6encodings byte-compiling C:Python26libencodingsaliases.py to encodingsaliases.pyc byte-compiling C:Python26libencodingsascii.py to encodingsascii.pyc byte-compiling C:Python26libencodingsbase64_codec.py to encodingsbase64_cod ec.pyc byte-compiling C:Python26libencodingsbig5.py to encodingsbig5.pyc byte-compiling C:Python26libencodingsbig5hkscs.py to encodingsbig5hkscs.pyc byte-compiling C:Python26libencodingsbz2_codec.py to encodingsbz2_codec.pyc byte-compiling C:Python26libencodingscharmap.py to encodingscharmap.pyc byte-compiling C:Python26libencodingscp037.py to encodingscp037.pyc byte-compiling C:Python26libencodingscp1006.py to encodingscp1006.pyc byte-compiling C:Python26libencodingscp1026.py to encodingscp1026.pyc byte-compiling C:Python26libencodingscp1140.py to encodingscp1140.pyc byte-compiling C:Python26libencodingscp1250.py to encodingscp1250.pyc byte-compiling C:Python26libencodingscp1251.py to encodingscp1251.pyc byte-compiling C:Python26libencodingscp1252.py to encodingscp1252.pyc byte-compiling C:Python26libencodingscp1253.py to encodingscp1253.pyc byte-compiling C:Python26libencodingscp1254.py to encodingscp1254.pyc byte-compiling C:Python26libencodingscp1255.py to encodingscp1255.pyc byte-compiling C:Python26libencodingscp1256.py to encodingscp1256.pyc byte-compiling C:Python26libencodingscp1257.py to encodingscp1257.pyc byte-compiling C:Python26libencodingscp1258.py to encodingscp1258.pyc byte-compiling C:Python26libencodingscp424.py to encodingscp424.pyc byte-compiling C:Python26libencodingscp437.py to encodingscp437.pyc byte-compiling C:Python26libencodingscp500.py to encodingscp500.pyc byte-compiling C:Python26libencodingscp737.py to encodingscp737.pyc byte-compiling C:Python26libencodingscp775.py to encodingscp775.pyc byte-compiling C:Python26libencodingscp850.py to encodingscp850.pyc byte-compiling C:Python26libencodingscp852.py to encodingscp852.pyc byte-compiling C:Python26libencodingscp855.py to encodingscp855.pyc byte-compiling C:Python26libencodingscp856.py to encodingscp856.pyc byte-compiling C:Python26libencodingscp857.py to encodingscp857.pyc byte-compiling C:Python26libencodingscp860.py to encodingscp860.pyc byte-compiling C:Python26libencodingscp861.py to encodingscp861.pyc byte-compiling C:Python26libencodingscp862.py to encodingscp862.pyc byte-compiling C:Python26libencodingscp863.py to encodingscp863.pyc byte-compiling C:Python26libencodingscp864.py to encodingscp864.pyc byte-compiling C:Python26libencodingscp865.py to encodingscp865.pyc byte-compiling C:Python26libencodingscp866.py to encodingscp866.pyc byte-compiling C:Python26libencodingscp869.py to encodingscp869.pyc byte-compiling C:Python26libencodingscp874.py to encodingscp874.pyc byte-compiling C:Python26libencodingscp875.py to encodingscp875.pyc byte-compiling C:Python26libencodingscp932.py to encodingscp932.pyc byte-compiling C:Python26libencodingscp949.py to encodingscp949.pyc byte-compiling C:Python26libencodingscp950.py to encodingscp950.pyc byte-compiling C:Python26libencodingseuc_jis_2004.py to encodingseuc_jis_20 04.pyc byte-compiling C:Python26libencodingseuc_jisx0213.py to encodingseuc_jisx02 13.pyc byte-compiling C:Python26libencodingseuc_jp.py to encodingseuc_jp.pyc byte-compiling C:Python26libencodingseuc_kr.py to encodingseuc_kr.pyc byte-compiling C:Python26libencodingsgb18030.py to encodingsgb18030.pyc byte-compiling C:Python26libencodingsgb2312.py to encodingsgb2312.pyc byte-compiling C:Python26libencodingsgbk.py to encodingsgbk.pyc byte-compiling C:Python26libencodingshex_codec.py to encodingshex_codec.pyc byte-compiling C:Python26libencodingshp_roman8.py to encodingshp_roman8.pyc byte-compiling C:Python26libencodingshz.py to encodingshz.pyc byte-compiling C:Python26libencodingsidna.py to encodingsidna.pyc byte-compiling C:Python26libencodingsiso2022_jp.py to encodingsiso2022_jp.p yc byte-compiling C:Python26libencodingsiso2022_jp_1.py to encodingsiso2022_jp _1.pyc byte-compiling C:Python26libencodingsiso2022_jp_2.py to encodingsiso2022_jp _2.pyc byte-compiling C:Python26libencodingsiso2022_jp_2004.py to encodingsiso2022 _jp_2004.pyc byte-compiling C:Python26libencodingsiso2022_jp_3.py to encodingsiso2022_jp _3.pyc byte-compiling C:Python26libencodingsiso2022_jp_ext.py to encodingsiso2022_ jp_ext.pyc byte-compiling C:Python26libencodingsiso2022_kr.py to encodingsiso2022_kr.p yc byte-compiling C:Python26libencodingsiso8859_1.py to encodingsiso8859_1.pyc byte-compiling C:Python26libencodingsiso8859_10.py to encodingsiso8859_10.p yc byte-compiling C:Python26libencodingsiso8859_11.py to encodingsiso8859_11.p yc byte-compiling C:Python26libencodingsiso8859_13.py to encodingsiso8859_13.p yc byte-compiling C:Python26libencodingsiso8859_14.py to encodingsiso8859_14.p yc byte-compiling C:Python26libencodingsiso8859_15.py to encodingsiso8859_15.p yc byte-compiling C:Python26libencodingsiso8859_16.py to encodingsiso8859_16.p yc byte-compiling C:Python26libencodingsiso8859_2.py to encodingsiso8859_2.pyc byte-compiling C:Python26libencodingsiso8859_3.py to encodingsiso8859_3.pyc byte-compiling C:Python26libencodingsiso8859_4.py to encodingsiso8859_4.pyc byte-compiling C:Python26libencodingsiso8859_5.py to encodingsiso8859_5.pyc byte-compiling C:Python26libencodingsiso8859_6.py to encodingsiso8859_6.pyc byte-compiling C:Python26libencodingsiso8859_7.py to encodingsiso8859_7.pyc byte-compiling C:Python26libencodingsiso8859_8.py to encodingsiso8859_8.pyc byte-compiling C:Python26libencodingsiso8859_9.py to encodingsiso8859_9.pyc byte-compiling C:Python26libencodingsjohab.py to encodingsjohab.pyc byte-compiling C:Python26libencodingskoi8_r.py to encodingskoi8_r.pyc byte-compiling C:Python26libencodingskoi8_u.py to encodingskoi8_u.pyc byte-compiling C:Python26libencodingslatin_1.py to encodingslatin_1.pyc byte-compiling C:Python26libencodingsmac_arabic.py to encodingsmac_arabic.p yc byte-compiling C:Python26libencodingsmac_centeuro.py to encodingsmac_centeu ro.pyc byte-compiling C:Python26libencodingsmac_croatian.py to encodingsmac_croati an.pyc byte-compiling C:Python26libencodingsmac_cyrillic.py to encodingsmac_cyrill ic.pyc byte-compiling C:Python26libencodingsmac_farsi.py to encodingsmac_farsi.pyc byte-compiling C:Python26libencodingsmac_greek.py to encodingsmac_greek.pyc byte-compiling C:Python26libencodingsmac_iceland.py to encodingsmac_iceland .pyc byte-compiling C:Python26libencodingsmac_latin2.py to encodingsmac_latin2.p yc byte-compiling C:Python26libencodingsmac_roman.py to encodingsmac_roman.pyc byte-compiling C:Python26libencodingsmac_romanian.py to encodingsmac_romani an.pyc byte-compiling C:Python26libencodingsmac_turkish.py to encodingsmac_turkish .pyc byte-compiling C:Python26libencodingsmbcs.py to encodingsmbcs.pyc byte-compiling C:Python26libencodingspalmos.py to encodingspalmos.pyc byte-compiling C:Python26libencodingsptcp154.py to encodingsptcp154.pyc byte-compiling C:Python26libencodingspunycode.py to encodingspunycode.pyc byte-compiling C:Python26libencodingsquopri_codec.py to encodingsquopri_cod ec.pyc byte-compiling C:Python26libencodingsraw_unicode_escape.py to encodingsraw_ unicode_escape.pyc byte-compiling C:Python26libencodingsrot_13.py to encodingsrot_13.pyc byte-compiling C:Python26libencodingsshift_jis.py to encodingsshift_jis.pyc byte-compiling C:Python26libencodingsshift_jis_2004.py to encodingsshift_ji s_2004.pyc byte-compiling C:Python26libencodingsshift_jisx0213.py to encodingsshift_ji sx0213.pyc byte-compiling C:Python26libencodingsstring_escape.py to encodingsstring_es cape.pyc byte-compiling C:Python26libencodingstis_620.py to encodingstis_620.pyc byte-compiling C:Python26libencodingsundefined.py to encodingsundefined.pyc byte-compiling C:Python26libencodingsunicode_escape.py to encodingsunicode_ escape.pyc byte-compiling C:Python26libencodingsunicode_internal.py to encodingsunicod e_internal.pyc byte-compiling C:Python26libencodingsutf_16.py to encodingsutf_16.pyc byte-compiling C:Python26libencodingsutf_16_be.py to encodingsutf_16_be.pyc byte-compiling C:Python26libencodingsutf_16_le.py to encodingsutf_16_le.pyc byte-compiling C:Python26libencodingsutf_32.py to encodingsutf_32.pyc byte-compiling C:Python26libencodingsutf_32_be.py to encodingsutf_32_be.pyc byte-compiling C:Python26libencodingsutf_32_le.py to encodingsutf_32_le.pyc byte-compiling C:Python26libencodingsutf_7.py to encodingsutf_7.pyc byte-compiling C:Python26libencodingsutf_8.py to encodingsutf_8.pyc byte-compiling C:Python26libencodingsutf_8_sig.py to encodingsutf_8_sig.pyc byte-compiling C:Python26libencodingsuu_codec.py to encodingsuu_codec.pyc byte-compiling C:Python26libencodingszlib_codec.py to encodingszlib_codec.p yc byte-compiling C:Python26libfunctools.py to functools.pyc byte-compiling C:Python26libgenericpath.py to genericpath.pyc byte-compiling C:Python26libgetopt.py to getopt.pyc byte-compiling C:Python26libgettext.py to gettext.pyc byte-compiling C:Python26libheapq.py to heapq.pyc byte-compiling C:Python26libinspect.py to inspect.pyc byte-compiling C:Python26libkeyword.py to keyword.pyc byte-compiling C:Python26liblinecache.py to linecache.pyc byte-compiling C:Python26liblocale.py to locale.pyc byte-compiling C:Python26libntpath.py to ntpath.pyc byte-compiling C:Python26libnumbers.py to numbers.pyc byte-compiling C:Python26libopcode.py to opcode.pyc byte-compiling C:Python26liboptparse.py to optparse.pyc byte-compiling C:Python26libos.py to os.pyc byte-compiling C:Python26libos2emxpath.py to os2emxpath.pyc byte-compiling C:Python26libpdb.py to pdb.pyc byte-compiling C:Python26libpickle.py to pickle.pyc byte-compiling C:Python26libposixpath.py to posixpath.pyc byte-compiling C:Python26libpprint.py to pprint.pyc byte-compiling C:Python26libquopri.py to quopri.pyc byte-compiling C:Python26librandom.py to random.pyc byte-compiling C:Python26libre.py to re.pyc byte-compiling C:Python26librepr.py to repr.pyc byte-compiling C:Python26libshlex.py to shlex.pyc byte-compiling C:Python26libsite-packageszipextimporter.py to zipextimporter .pyc byte-compiling C:Python26libsre.py to sre.pyc byte-compiling C:Python26libsre_compile.py to sre_compile.pyc byte-compiling C:Python26libsre_constants.py to sre_constants.pyc byte-compiling C:Python26libsre_parse.py to sre_parse.pyc byte-compiling C:Python26libstat.py to stat.pyc byte-compiling C:Python26libstring.py to string.pyc byte-compiling C:Python26libstringprep.py to stringprep.pyc byte-compiling C:Python26libstruct.py to struct.pyc byte-compiling C:Python26libsubprocess.py to subprocess.pyc byte-compiling C:Python26libtempfile.py to tempfile.pyc byte-compiling C:Python26libtextwrap.py to textwrap.pyc byte-compiling C:Python26libthreading.py to threading.pyc byte-compiling C:Python26libtoken.py to token.pyc byte-compiling C:Python26libtokenize.py to tokenize.pyc byte-compiling C:Python26libtraceback.py to traceback.pyc byte-compiling C:Python26libtypes.py to types.pyc byte-compiling C:Python26libunittest.py to unittest.pyc byte-compiling C:Python26libwarnings.py to warnings.pyc *** copy extensions *** copying C:Python26DLLsbz2.pyd -> C:Python26workingbuildbdist.win32winexe collect-2.6 copying C:Python26DLLsselect.pyd -> C:Python26workingbuildbdist.win32win execollect-2.6 copying C:Python26DLLsunicodedata.pyd -> C:Python26workingbuildbdist.win3 2winexecollect-2.6 copying C:Python26libsite-packagescx_Oracle.pyd -> C:Python26workingbuild bdist.win32winexecollect-2.6 *** copy dlls *** copying C:OracleXEClientbinOCI.dll -> C:Python26workingbuildbdist.win32 winexecollect-2.6 copying C:Python26libsite-packagespy2exerun.exe -> C:Python26workingdist testora.exe *** binary dependencies *** Your executable(s) also depend on these dlls which are not included,you may or may not need to distribute them. Make sure you have the license if you distribute any of them,and make sure you don't distribute files belonging to the operating system. USER32.dll - C:WINDOWSsystem32USER32.dll SHELL32.dll - C:WINDOWSsystem32SHELL32.dll WSOCK32.dll - C:WINDOWSsystem32WSOCK32.dll ADVAPI32.dll - C:WINDOWSsystem32ADVAPI32.dll msvcrt.dll - C:WINDOWSsystem32msvcrt.dll KERNEL32.dll - C:WINDOWSsystem32KERNEL32.dll C:Python26workingdist>testora Traceback (most recent call last): File "testora.py",line 19,in <module> File "testora.py",line 11,in testora cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle 解决方法
您是否确保在使用py2exe构建时排除OCI.dll?如果您机器上的DLL版本与另一台机器上的客户端版本不兼容,那么您测试它(我注意到您在机器上尝试了11g客户端但是10g),那么此配置将无法工作(我忘记了实际的错误消息)虽然).
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |