Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pandas、SQLalchemy和子进程SQL*加载程序冲突_Python_Python 3.x_Pandas_Sqlalchemy_Sql Loader - Fatal编程技术网

Python Pandas、SQLalchemy和子进程SQL*加载程序冲突

Python Pandas、SQLalchemy和子进程SQL*加载程序冲突,python,python-3.x,pandas,sqlalchemy,sql-loader,Python,Python 3.x,Pandas,Sqlalchemy,Sql Loader,我有一个简短的Python脚本,可以查询Oracle数据库并使用Pandas数据帧将结果保存到CSV。然后,我尝试通过子进程调用调用SQL*Loader,将csv文件导入另一个数据库。这两个步骤都可以独立工作。但是,在同一脚本中,子进程调用失败 这是我的代码的截断副本: import pandas as pd import pandas.io.sql as psql from sqlalchemy import create_engine import subprocess # Create

我有一个简短的Python脚本,可以查询Oracle数据库并使用Pandas数据帧将结果保存到CSV。然后,我尝试通过子进程调用调用SQL*Loader,将csv文件导入另一个数据库。这两个步骤都可以独立工作。但是,在同一脚本中,子进程调用失败

这是我的代码的截断副本:

import pandas as pd
import pandas.io.sql as psql
from sqlalchemy import create_engine
import subprocess

# Create database connections
cxnAspect = create_engine('oracle+cx_oracle://user:pass@TNS')

# Set control strings
filename = 'export.csv'
filepath = 'C:/temp/'
sqlldr = 'C:/Oracle/product/11.2.0/client_1/BIN/sqlldr'
dblogin = 'userid=user/pass@TNS'
ctlfile = 'control=C:/Temp/control.ctl'
datafile = 'data=C:/Temp/data.csv'    

# Load query
sqlStr = """SELECT <snip>"""

# Load query result into dataframe
df = psql.read_sql_query(sqlStr, cxnAspect) #! If this line is removed, issue is resolved

# Write dataframe to CSV file
df.to_csv(filepath+filename, header = False, index=False)

# Load CSV file to database with SQL Loader
with open('stdout.txt', 'wb') as out:
    with open('stderr.txt', 'wb') as err:
        # subprocess.call([sqlldr, dblogin, ctlfile, datafile, stdout=out, stderr=err)
这似乎暗示了环境变量的问题,但我无法将其与subprocess.call在独立脚本中正常工作这一事实相协调


你知道为什么read_sql_query()会导致sql*Loader失败吗?

好的,我重写了代码,完全使用cx_Oracle直接访问数据库来删除Pandas,但问题仍然存在。我找到了一个解决方法,使用多处理,在不同的进程中运行转储到csv和从csv导入。为了找出原因,我不完全理解这一点的含义,但目前,我有一些有效的方法。
Message 2100 not found; No message file for product=RDBMS, facility=ULMessage 2100 not found; No message file for product=RDBMS, facility=UL