Tuesday, 11 February 2020

python 2.7 - OSgeo4W64 Windows 7 & ImportError: No Module Named Site


I realize this question has been asked a lot, but I was not able to resolve my issue through the answers posted elsewhere... I am new to Python, gdal, OSgeo4W, etc. but have experience with ArcGIS.


I'm receiving the dreaded "ImportError: No module named site" error from Windows Cmd after running the following batch file by clicking on it directly from windows explorer (it is save as a .bat file).



ECHO Off
C:\OSGeo4W64\bin\gdalbuildvrt.exe depth_max.vrt *.tif
python C:\OSGeo4W64\bin\gdal2tiles.py -s EPSG:2278 -z 12 -w none "depth_max.vrt" depth_max
pause




Couple observations/comments:



  • The file runs fine when running it from the OSgeo4W window

  • gdalbuildvrt.exe executes fine in either scenario, the error is associated with the python command

  • Python 2.7 is installed at C:\Python27\ArcGIS10.2\ and C:\OSGeo4W64\apps\Python27

  • Python 3.6 is installed at C:\OSGeo4W64\apps\Python36

  • Running Windows 7 (Note: This may be run on Windows 10 as well)

  • gdalbuildvrt does not have a .py file; only .exe, which I found odd but I guess it is not a python script but a standalone program?

  • I tried including the SET commands for PYTHONHOME and PYTHONPATH in the batch file and it either did not work or broke python (it would then say DLLs were not found)



My eventual goal is to run this from a SHELL command via another program.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...