我从
ImportError: No module named cx_Oracle
调用 test.py
时收到 call_test.py
错误。如果我直接执行test.py
,效果很好。
以下是代码:
db_connection.py
import cx_Oracle
from configparser import ConfigParser
config = ConfigParser()
config.read('config_dev.ini')
db_config = config['database']
dsn = cx_Oracle.makedsn(db_config['host'], db_config['port'], service_name=db_config['service_name'])
connection = cx_Oracle.connect(user=db_config['username'], password=db_config['password'], dsn=dsn)
测试.py
import db_connection as db
if __name__ == '__main__':
cursor = db.connection.cursor()
querystring = "select * from dual"
cursor.execute(querystring)
res = cursor.fetchall()
for row in res:
print(row)
call_test.py
import subprocess
subprocess.call(["python", "test.py"])
尝试安装模块:
pip install cx_oracle