0
我寫了一個很簡單的Python腳本(db.py):pyinstaller包cx_Oracle問題(在CentOS)
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import cx_Oracle
dsn_tns = cx_Oracle.makedsn("192.168.100.15", "1521", "zhy")
print dsn_tns
conn = cx_Oracle.connect("winvoice", "winvoice", dsn_tns)
cursor = conn.cursor()
print cursor
它運行在控制檯確定:
[[email protected] 1]$ ./db.py
/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py:1256: UserWarning: /home/ddgg/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.15)(PORT=1521)))(CONNECT_DATA=(SID=zhy)))
<cx_Oracle.Cursor on <cx_Oracle.Connection to [email protected](DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.15)(PORT=1521)))(CONNECT_DATA=(SID=zhy)))>>
[[email protected] 1]$
然後我包裝它使用pyinstaller ,只需用:pyinstaller db.py
, 然後db.spec
生成:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['db.py'],
pathex=['/workcopy/sae/rtgame/1'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None,
excludes=None,
cipher=block_cipher)
pyz = PYZ(a.pure,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='db',
debug=False,
strip=None,
upx=True,
console=True)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=None,
upx=True,
name='db')
它沒有錯誤,但是當我運行它時,我得到:
[[email protected] 1]$ dist/db/db
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named cx_Oracle
[[email protected] 1]$
怎麼回事? 在Python控制檯,cx_Oracle可以正確導入:
[[email protected] 1]$ python
Python 2.7.10 (default, Sep 10 2015, 14:06:03)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py:1256: UserWarning: /home/ddgg/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
任何想法?謝謝。
執行'import cx_Oracle;在_Python_交互式shell中打印cx_Oracle .__ file__'? – Yoel
@Yoel感謝您的關注。 '>>> print cx_Oracle .__ file__'I: '/ home/ddgg/.python-eggs/cx_Oracle-5.2-py2.7-linux-x86_64.egg-tmp/cx_Oracle.so' – DDGG