我正在为 python 代码和终端使用 anaconda 环境。
当我想在环境激活的情况下在 shell (Windows CMD) 中执行程序时。程序 ogr2ogr 使用给定的参数返回正确的输出。工具 ogr2ogr 已通过 conda 包安装。
但是当我执行我的 python 代码时, ogr2ogr 返回错误输出。我认为这可能是由于使用了不同的环境(在我不知情的情况下)而使用的不同安装,但这只是一个猜测。
python代码如下:
from pathlib import Path
from subprocess import check_call, STDOUT
...
file_path = Path(file_name)
destination = str(file_path.with_suffix(".gpkg"))
command = f"ogr2ogr -f GPKG -s_srs EPSG:25833 -t_srs EPSG:25833 {destination} GMLAS:{file_name} -oo REMOVE_UNUSED_LAYERS=YES"
check_call(command, stderr=STDOUT, shell=True)
ogr2ogr 将文件转换为另一种格式。这也完成了,但是当我打开文件时,我看到它并没有 100% 正确完成。当我复制字符串命令的值并将其复制到 shell 并执行命令时,执行正确完成!
如何纠正使用 subprocess.check_call 的行为