[Qgis-user] Python Path
Leo Kris Palao
lk.palao at gmail.com
Sun Aug 10 19:40:04 PDT 2014
Hi QGIS users,
Good Day!
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.
I converted the OSGeo4W shell to a python shell using the python command.
C:\> python
Then I execute my file >>>
execfile('folderpath\\multiband_zonalstat_pythonshell.py')
*Then it throws an error:*
*Traceback (most recent call last):*
* File "<stdin>", line 1, in <module>*
* File "folderpath\multiband_zonalstat_pythonshell.py", line 1, in <modul*
*e>*
* import qgis.analysis*
This is the script that I am trying to run in python shell:
import qgis.analysis
vectorlayer = QgsVectorLayer(r"folderpath/YEU.shp", "Ye-U", "ogr")
rasterfile = "rasterpath/cdz_raw_image.img"
for num in range(1):
zonalstats =
qgis.analysis.QgsZonalStatistics(vectorlayer,rasterfile,str(num),num)
zonalstats.calculateStatistics(None)
I tried checking the system path (please see below), and I think it can
locate my OSGeo python installation path.
I also tried editing my system variables path and include the OSGeo python,
and OSGeo QGIS path but still it throws the same error.
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.
On the other hand, I also tried to include the following lines in the
beginning of my script with no success:
*import sys*
*sys.path.extend([r'C:\OSGeo4W\apps\qgis\python',
r'C:\OSGeo4W\apps\qgis\bin'])*
it throws this error:
*Traceback (most recent call last):*
* File "<stdin>", line 1, in <module>*
* File "E:\Python_scripts\multiband_zonalstat_pythonshell.py", line 3, in
<modul*
*e>*
* import qgis.analysis*
* File "C:\OSGeo4W\apps\qgis\python\qgis\__init__.py", line 35, in
<module>*
* from qgis.core import QgsFeature, QgsGeometry*
*ImportError: DLL load failed: The specified module could not be found.*
I am not sure why it can't find qgis.analysis module or is there something
wrong with my script.
Thanks for the help and clarification,
-Leo
GDAL 1.10.1, released 2013/08/26
C:\>python
Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]
on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\OSGeo4W\\apps\\orfeotoolbox\\wrapping\\lib',
'C:\\OSGeo4W\\apps\\orfeo
toolbox\\wrapping\\Python', 'C:\\OSGeo4W\\apps\\orfeotoolbox\\python',
'C:\\', '
C:\\OSGeo4W\\bin\\python27.zip', 'C:\\OSGeo4W\\apps\\Python27\\DLLs',
'C:\\OSGeo
4W\\apps\\Python27\\lib', 'C:\\OSGeo4W\\apps\\Python27\\lib\\plat-win',
'C:\\OSG
eo4W\\apps\\Python27\\lib\\lib-tk', 'C:\\OSGeo4W\\bin',
'C:\\OSGeo4W\\apps\\Pyth
on27', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages',
'C:\\OSGeo4W\\apps\\Py
thon27\\lib\\site-packages\\PIL',
'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packag
es\\win32', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\win32\\lib',
'C:\\
OSGeo4W\\apps\\Python27\\lib\\site-packages\\Pythonwin',
'C:\\OSGeo4W\\apps\\Pyt
hon27\\lib\\site-packages\\Shapely-1.2.18-py2.7-win32.egg',
'C:\\OSGeo4W\\apps\\
Python27\\lib\\site-packages\\wx-2.8-msw-unicode']
>>> execfile('E:\\folderpath\\multiband_zonalstat_pytonshell.py')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'folderpath\\multiband_zon
alstat_pytonshell.py'
>>> execfile('fodlerpath\\multiband_zonalstat_pythonshell.py')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "folderpath\multiband_zonalstat_pythonshell.py", line 1, in <modul
e>
import qgis.analysis
ImportError: No module named qgis.analysis
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140811/7f26203f/attachment.html>
More information about the Qgis-user
mailing list