错误:在 python 脚本中运行 ogr2ogr 时,“ogr2ogr"未被识别为内部或外部命令、可运行的程序或批处理文件 [英] ERROR: 'ogr2ogr' is not recognized as an internal or external command, operable program or batch file when running ogr2ogr in python script

查看:156
本文介绍了错误:在 python 脚本中运行 ogr2ogr 时,“ogr2ogr"未被识别为内部或外部命令、可运行的程序或批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试通过子进程运行 ogr2ogr 时出错,但我可以仅使用 Windows 命令提示符运行它.该脚本将是一系列进程的一部分,这些进程从批量导入 gpx 文件到 postgres 数据库开始.有人可以告诉我有什么问题吗?谢谢!

::::::::::::::::::::::::::::运行这个脚本给我一个错误:'ogr2ogr' 不是内部或外部命令,也不是可运行的程序或批处理文件.

<块引用>

导入子进程

导入系统

打印 sys.executable

track="20131007.gpx"

subprocess.call(["ogr2ogr", "-f", "PostgreSQL", "PG:dbname=TTBASEMain host=localhost port=5432 user=postgres password=minda", track], shell=True)

::::::::::::::::::::::::::::::这段代码很好地完成了它的工作.

<块引用>

ogr2ogr -f PostgreSQL PG:"dbname='TTBASEMain' host='localhost' port='5432' user='postgres' password='minda'" "20131007.gpx"

::::::::::::::::::::::::::::::这是我在我的环境路径中所拥有的:

<块引用>

C:\Users\User>路径PATH=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R)Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\lastools\bin;C:\Python27;C:\Python27\Scripts;C:\Python27\DLLs;C:\Python27\Lib\site-packages;C:\Users\User\AppData\Roaming.local\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\GDAL

解决方案

重新安装 python 绑定解决了我的问题.我在下面的路径上没有看到 GDAL,但它现在正在工作.它应该在那里,因为它不在,我可能在未来有另一轮 GDAL 挠头?

::::::::::::::::::::::::::::::::::::::::这是我当前在 python 上输入 sys.path 时所拥有的:

<块引用>

Microsoft Windows [版本 6.2.9200](c) 2012 年微软公司.保留所有权利.

C:\Users\User>pythonPython 2.7.8(默认,2014 年 6 月 30 日,16:08:48)[MSC v.1500 64 位 (AMD64)] on win32输入帮助"、版权"、信用"或许可"以了解更多信息.

<块引用><块引用>

导入系统系统路径['', 'C:\windows\SYSTEM32\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\lib-tk', 'C:\Python27', 'C:\Python27\lib\site-packages', 'C:\Python27\lib\site-packages\wx-3.0-msw']

I get an error when trying to run ogr2ogr thru subprocess but I am able to run it using just the windows command prompt. The script will be part of a series of processes that start with batch importing gpx files unto a postgres db. Can somebody please tell me what's wrong? Thanks!

:::::::::::::::::::::::::::: Running THIS script gives me an ERROR: 'ogr2ogr' is not recognized as an internal or external command, operable program or batch file.

import subprocess

import sys

print sys.executable

track= "20131007.gpx"

subprocess.call(["ogr2ogr", "-f", "PostgreSQL", "PG:dbname=TTBASEMain host=localhost port=5432 user=postgres password=minda", track], shell=True)

::::::::::::::::::::::::::::: THIS CODE does its job well.

ogr2ogr -f PostgreSQL PG:"dbname='TTBASEMain' host='localhost' port='5432' user='postgres' password='minda'" "20131007.gpx"

::::::::::::::::::::::::::::: THIS is what I have in my environment path:

C:\Users\User>path PATH=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine C omponents\IPT;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\lastools\bin;C:\Python27;C:\Python27\Scripts;C:\Python27\DLLs;C:\Python27\Lib\site-packages;C:\Users\User\AppData\Roaming.local\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\GDAL

解决方案

REINSTALLING the python bindings resolved my issue. I don't see GDAL on the paths below but its working now. Is it supposed to be there so since its not, I might probably have another round of GDAL head scratching in the future?

::::::::::::::::::::::::::::::::::::::: THIS is what I currently have when I type in sys.path on python:

Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\User>python Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import sys sys.path ['', 'C:\windows\SYSTEM32\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27 \lib\plat-win', 'C:\Python27\lib\lib-tk', 'C:\Python27', 'C:\Python27\lib\site-packages', ' C:\Python27\lib\site-packages\wx-3.0-msw']

这篇关于错误:在 python 脚本中运行 ogr2ogr 时,“ogr2ogr"未被识别为内部或外部命令、可运行的程序或批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆