导入错误:没有名为 cx_Oracle 的模块

问题描述 投票:0回答:1

我从

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"])
python python-3.x cx-oracle
1个回答
0
投票

尝试安装模块:

pip install cx_oracle
© www.soinside.com 2019 - 2024. All rights reserved.