3

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:

ulrich
  • 1,431
  • 3
  • 17
  • 46
  • Why are you hand installing modules? Why aren't you using easy_install or pip (use pip)? – Marcin May 02 '15 at 17:20
  • @Marcin As you can see, I am trying to make my way through the setup. I am not aiming to do manual install nor have I done so. So far I have just executed what's in the manual and trying to find the sip module dependencies. – ulrich May 02 '15 at 17:30
  • @Marcin thanks, I made it to get pip running, using this [tutorial](http://quantumofgis.blogspot.de/2014/11/qgis-standalone-and-python-modules.html). When I try to install sip like this: `pip install --allow-external "sip>=4.16"`, I get the error `You must give at least one requirement to install`. Do you see, if my command is incorrect? – ulrich May 02 '15 at 18:36
  • just do `pip install SIP`. SIP is at pypi here: https://pypi.python.org/pypi/SIP/4.16.7 – Marcin May 02 '15 at 18:42
  • well, tried that first, giving me `No matching distribution found for sip`. Now I also tried `pip install "https://pypi.python.org/pypi/SIP/4.16.7"` showing `Downloading 4.16.7 Cannot unpack file c:\users\user\appdata\local\temp\pip-bu5yei-unpack\4.16.7 cannot detect archive format`... – ulrich May 02 '15 at 19:36
  • 2
    I just tried to install it. I think the problem might be that this software is a piece of turd. Consider if you can use something else. – Marcin May 02 '15 at 20:09

1 Answers1

4

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.

Community
  • 1
  • 1
ulrich
  • 1,431
  • 3
  • 17
  • 46