Can't get Python IDLE to recognize OGR/GDAL Module

落花浮王杯 提交于 2019-12-11 02:19:01

问题


Folks,

Just getting started using OGR and Python for a variety of geospatial tasks. I'm working outside of OSGEO4w, and have installed GDAL w/ Python Bindings as well as Python v. 2.7.8 on my machine.

That said, I can run python and import gdal from a command-line interface but am unable to import the module when I use the IDLE environment. It returns an error telling me that the module doesn't exist. My install must be sound given that it works in the cmd prompt, so what's the deal?

This is all new to me, I'd appreciate any help or advice ya'll can impart; all previous questions I've read were concerned w/ merely installing (which I've done successfully) and getting Python to recognize the module from the command prompt, which it does.

Cheers,

Mike


回答1:


Mike,

You can open IDLE with your python installation from the cmd line through:

>>>from idlelib import PyShell  
>>>PyShell.main()

This should open IDLE from your current python, and you should be able then to import gdal and ogr from there.

Alternatively, you should have a windows batch file here C:\YOURPYTHONPATH\Lib\idlelib\idle.bat

Running this should achieve the same.

Martin




回答2:


Consider creating the following batch where PyInst references the Python installation folder from which IDLE is launched (i.e. idle.bat) and QgisInst references the folder containing "bin\o4w_env.bat":

@echo off
set PyInst=C:\Python27
set QgisInst="C:\Program Files\QGIS Brighton"

call %QgisInst%\bin\o4w_env.bat
set PYTHONPATH=%PyInst%\DLLs;%PyInst%\Lib;%PyInst%\Lib\lib-tk
set TCL_LIBRARY=%PyInst%\tcl\tcl8.5
python %PyInst%\Lib\idlelib\idle.pyw


来源:https://stackoverflow.com/questions/25836182/cant-get-python-idle-to-recognize-ogr-gdal-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!