<div dir="ltr">Hi QGIS users,<div><br></div><div>Good Day!</div><div><br></div><div>Would like to ask how can I execute my python script in Python Shell? It keeps on asking me that the module that I am using does not exist.</div>

<div><br></div><div>I converted the OSGeo4W shell to a python shell using the python command.</div><div>C:\> python</div><div><br></div><div>Then I execute my file >>> execfile('folderpath\\multiband_zonalstat_pythonshell.py')</div>

<div><br></div><div><i>Then it throws an error:</i></div><div><div><i>Traceback (most recent call last):</i></div><div><i>  File "<stdin>", line 1, in <module></i></div><div><i>  File "folderpath\multiband_zonalstat_pythonshell.py", line 1, in <modul</i></div>

<div><i>e></i></div><div><i>    import qgis.analysis</i></div></div><div><br></div><div>This is the script that I am trying to run in python shell:</div><div><br></div><div><div>import qgis.analysis</div><div>vectorlayer = QgsVectorLayer(r"folderpath/YEU.shp", "Ye-U", "ogr")</div>

<div>rasterfile = "rasterpath/cdz_raw_image.img"</div><div>for num in range(1):</div><div><span class="" style="white-space:pre">     </span>zonalstats = qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,str(num),num)</div>

<div><span class="" style="white-space:pre">    </span>zonalstats.calculateStatistics(None)</div></div><div><div><br></div><div>I tried checking the system path (please see below), and I think it can locate my OSGeo python installation path.</div>

<div><br></div><div>I also tried editing my system variables path and include the OSGeo python, and OSGeo QGIS path but still it throws the same error.</div><div><br></div><div>I am trying to run my script in a python shell to test if the processing time will be much shorter compare to running it in the python console in QGIS.</div>

<div><br></div><div>On the other hand, I also tried to include the following lines in the beginning of my script with no success:</div><div><div><i>import sys</i></div><div><i>sys.path.extend([r'C:\OSGeo4W\apps\qgis\python', r'C:\OSGeo4W\apps\qgis\bin'])</i></div>

</div><div><br></div><div>it throws this error:</div><div><br></div><div><div><i>Traceback (most recent call last):</i></div><div><i>  File "<stdin>", line 1, in <module></i></div><div><i>  File "E:\Python_scripts\multiband_zonalstat_pythonshell.py", line 3, in <modul</i></div>

<div><i>e></i></div><div><i>    import qgis.analysis</i></div><div><i>  File "C:\OSGeo4W\apps\qgis\python\qgis\__init__.py", line 35, in <module></i></div><div><i>    from qgis.core import QgsFeature, QgsGeometry</i></div>

<div><i>ImportError: DLL load failed: The specified module could not be found.</i></div></div><div><br></div><div>I am not sure why it can't find qgis.analysis module or is there something wrong with my script.</div>
<div>
<br></div><div>Thanks for the help and clarification,</div><div>-Leo</div><div><br></div><div><div>GDAL 1.10.1, released 2013/08/26</div><div><br></div><div>C:\>python</div><div>Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win</div>

<div>32</div><div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> import sys</div><div>>>> sys.path</div><div>['', 'C:\\OSGeo4W\\apps\\orfeotoolbox\\wrapping\\lib', 'C:\\OSGeo4W\\apps\\orfeo</div>

<div>toolbox\\wrapping\\Python', 'C:\\OSGeo4W\\apps\\orfeotoolbox\\python', 'C:\\', '</div><div>C:\\OSGeo4W\\bin\\python27.zip', 'C:\\OSGeo4W\\apps\\Python27\\DLLs', 'C:\\OSGeo</div>

<div>4W\\apps\\Python27\\lib', 'C:\\OSGeo4W\\apps\\Python27\\lib\\plat-win', 'C:\\OSG</div><div>eo4W\\apps\\Python27\\lib\\lib-tk', 'C:\\OSGeo4W\\bin', 'C:\\OSGeo4W\\apps\\Pyth</div><div>on27', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages', 'C:\\OSGeo4W\\apps\\Py</div>

<div>thon27\\lib\\site-packages\\PIL', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packag</div><div>es\\win32', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\</div><div>OSGeo4W\\apps\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\OSGeo4W\\apps\\Pyt</div>

<div>hon27\\lib\\site-packages\\Shapely-1.2.18-py2.7-win32.egg', 'C:\\OSGeo4W\\apps\\</div><div>Python27\\lib\\site-packages\\wx-2.8-msw-unicode']</div><div>>>> execfile('E:\\folderpath\\multiband_zonalstat_pytonshell.py')</div>

<div>Traceback (most recent call last):</div><div>  File "<stdin>", line 1, in <module></div><div>IOError: [Errno 2] No such file or directory: 'folderpath\\multiband_zon</div><div>alstat_pytonshell.py'</div>

<div>>>> execfile('fodlerpath\\multiband_zonalstat_pythonshell.py')</div><div>Traceback (most recent call last):</div><div>  File "<stdin>", line 1, in <module></div><div>  File "folderpath\multiband_zonalstat_pythonshell.py", line 1, in <modul</div>

<div>e></div><div>    import qgis.analysis</div><div>ImportError: No module named qgis.analysis</div><div>>>></div></div></div></div>