2009-10-08 9 views
10

나는 gdal 설치하고 우분투 말쑥한에서 실행하지만 난 오류 얻을 수 있기 때문에 gdal2tiles를 실행할 수있다 : 나는 파이썬을 열 때파이썬에서 gdal을 가져올 수 없습니까?

Traceback (most recent call last): 
    File "/usr/local/bin/gdal2tiles.py", line 42, in <module> 
    import gdal 
ImportError: No module named gdal 

을 내가 같은 오류가 import gdal을 입력합니다.

나는 set LD_LIBRARY_PATH (공백없이!)에서 /usr/local/lib으로 변경되었지만 차이점이없는 것으로 보입니다.

파이썬이 gdal을 찾을 수없는 것 같습니다. 누구든지 도와 줄 수 있습니까?

감사합니다.

답변

14

Ith는 "파이썬 경로"인 것 같습니다.   파이썬 라이브러리는 정의 된 경로 내에서 검색됩니다. 시도해보십시오.

import sys 
sys.path 

gdal.py 및 관련 파일이이 목록에 없으면 Python에서 찾을 수 없습니다. 그것은 "진단"부분입니다. 상황을 수정하기 위해 몇 가지 옵션이 있습니다 ... 모두 파이썬이이 경로를 만드는 데 사용하는 규칙을 알고 있어야합니다.

  • PYTHONPATH의 environement 변수

  • 파이썬 디렉토리 원하는 라이브러리 상주에서 시작할 수 있습니다 원하는 경로를 포함하도록 변경 될 수 있습니다.
  • 의 sys.path 동적 sys.path.append와 ("/ somepath는 /로/mystuff에"), 변경할 수 있습니다

내가 SYS의 건물에 관한 규정을 본 적이있는 유일한 장소. 경로는 이전 섹션의 tutorial에, "공식적인"파이썬 문서에서 설명 6.1.2
발췌 :

다음
 
modules are searched in the list of directories given by the variable sys.path 
which is initialized from the directory containing the input script (or the 
current directory), PYTHONPATH and the installation- dependent default. This 
allows Python programs that know what they’re doing to modify or replace the 
module search path. Note that because the directory containing the script being 
run is on the search path, it is important that the script not have the same name 
as a standard module, or Python will attempt to load the script as a module when 
that module is imported. This will generally be an error. See section 
Standard Modules for more information. 
+0

감사! PYTHONPATH에 gdal 라이브러리를 추가하면 'export PYTHONPATH = "..."를 사용하여 문제가 해결되었습니다. – AP257

+0

Windows에서 PYTHONPATH라는 변수가 없으면 경로를 추가하십시오. – Roozi

+1

어떻게 PYTHONPATH 환경을 수정하여이 문제를 해결합니까? 모듈이 저장된 위치 나 'PYTHONPATH'변수를 편집하는 방법을 찾을 수 없습니다. – mjp

6

어떻게 설치하고 파이썬 + GDAL를 사용하도록 가르치는 링크입니다 , OGR 및 기타 그렇소.

유용하게 사용하겠습니다.

http://www.gis.usu.edu/~chrisg/python/2009/

+0

또한 사용중인 버전에주의하십시오. –

1

은 또한 파이썬 바인딩에 전념 GDAL 위키을 확인 할 수 있습니다 - GdalOgrInPython Linux 및 Windows 플랫폼에서 설치 및 사용이 논의된다.

관련 문제