I have QGIS Valmiera 2.2.0 installed and started a simple python script using this documentation.
I had a hard time because always when I used
from qgis.core import *
I got the message ImportError: No module named qgis.core. I fixed that with the statement
sys.path.extend([r"C:\Program Files (x86)\QGIS Valmiera\apps\qgis\python"])
using the correct python path. Then I expected it to work but I ran into the next error message:
ImportError: No module named sip
I tried to do the same again, adding subfolders of qgis, which might be connected to sip, but without success.
sys.path.extend([r"C:\Program Files (x86)\QGIS Valmiera\apps\Python27",
r"C:\Program Files (x86)\QGIS Valmiera\apps\Qt4",
r"C:\Program Files (x86)\QGIS Valmiera\apps\Python27\sip",
r"C:\Program Files (x86)\QGIS Valmiera\apps\Python27\sip\PyQt4",
r"C:\Users\Downloads\sip-4.16.7\sip-4.16.7"])
The sip.exe, which I guess it is looking for, is actually located in the C:\Program Files (x86)\QGIS Valmiera\apps\Python27 path.
Is there anything missing in the pre-installed functionality or what might be the problem?
Thanks for any hints!
UPDATE: For anyone interested: I did the following steps for installing sip library, without final success so far:
pip install sip giving error InsecurePlatformWarningYou must give at least one requirement to installpip install http://sourceforge.net/projects/pyqt/files/sip/sip-4.16.7/sip-4.16.7.zip giving
IOError: [Errno 2] No such file or directory: 'c:\users\user\appdata\local\temp\pip-d92iiw-build\setup.py'
Command "python setup.py egg_info" failed with error code 1 in c:\users\user\appdata\local\temp\pip-d92iiw-build
Tried installing contained configure.py from pip-d92iiw-build manually. Also no success
Got it working now thanks to the answer to my question here.
Actually, it seems like the sip library is really packed with the QGIS distribution but for running a script there it's not only necessary to setup PATH and PYTHONPATH correctly but also to call o4w_env.bat, otherwise it will not be found.
So it is possible to use the bat script from the answer for setting up everything and then calling the python script afterwards which will then be able to use sip and everything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With