I want to load a text file (TSV, tab-separated values) to SQL Server using Microsoft's Bulk Copy Program (BCP) utility. I want to call BCP in a python script via python's subprocess
module.
Here's the command I'm entering:
subprocess.check_output(['bcp', 'TEST_load_hh20220818', 'in', 'C:\\Users\\xxxx\\some-folder\\_household.tsv', '-S', 'SQL-SVR', '-d', 'MTP2024', '-T', '-q', '-c', '-t', '\\t', '-F', '2'])
But when I run it, I get the error:
*** FileNotFoundError: [WinError 2] The system cannot find the file specified
So far I tried the following:
Confirmed that the file path is correct by running
os.path.exists('C:\\Users\\xxxx\\some-folder\\_household.tsv')
and also successfully loading the file into a Pandas dataframe--again, just to confirm that the file path is correct.Successfully ran the script on three other computers, making me suspect it is a machine issue and not a syntax/script error. All machines that I tested on are running Windows 10.
Tried adding
shell=True
to thesubprocess.check_output()
parameters, as suggested on this thread. This did not fix the issue.
Any idea what's going on?