1

I am developing a standalone app (in Windows) using libraries from QGIS. When I run the script in cmd, I get the ImportError: no module named qgis.core. I read in several posts that I need to configure the PYTHONPATH and PATH but I also read that with OSGEO4W installation there is no need to configure.

How do I do that?

I am very confused and I try several ways but without success. Now I am reinstalling QGIS thorugh OSGEO4W.

So, I need to import QGIS libraries in a script outside QGIS. This script runs inside Python27 folder that I have already installed for other app.

Is it possible to use the QGIS libraries through this directory?

If not what is the solution?


I resolved the import qgis.core error, just following the instructions of how to import qgis modules outside qgis. Now the error is different: ImportError: DLL load failed: %1 is not a valid Win32 application. And the error is related with import sip. I search and find that I use python from OSGEO4W (64bits) and external python (32 bits).

How I can solve it?

5
  • look at A Quick Guide to Getting Started with PyQGIS on Windows for example
    – gene
    Mar 11, 2015 at 17:59
  • I try with the instructions in "Setting the environment" section but when I opne that file (such as refered) the comand line (cmd) doesn't open. Also I don't know what to put in PATH in my case. Mar 12, 2015 at 14:33
  • Ok, I try to run as administartor and I get it. But the error is still the same. Mar 12, 2015 at 14:43
  • how are you calling this script form cmd? are you setting the variables on the command before executing?
    – vinayan
    Mar 16, 2015 at 11:52
  • 1
    Yes. I am calling the script from cmd and before that I set the variables like this: set PYTHONPATH=C:\OSGeo4W64\apps\qgis\python set PATH=C:\OSGeo4W64\apps\qgis\bin;%PATH% Mar 16, 2015 at 12:02

3 Answers 3

2

I'm not sure if it helps for you but in principle you set paths either by writing the commands into the DOS-box (started with cmd) or by setting them via a batch file. To use eclipse with QGIS the following lines have been recommended. All you have to do is to write them into a plain text file and give its filename a .bat ending.

Just make sure to replace by your own file names. Instead of eclipse.exe (last line) use your standalone app:

call "C:\Program Files (x86)\QGIS Wien\bin\o4w_env.bat"  
set PATH=%PATH%;C:\Program Files (x86)\QGIS Wien\apps\qgis\bin;C:\Program Files (x86)\QGIS Wien\bin  
SET PYTHONHOME=C:\Program Files (x86)\QGIS Wien\apps\Python27  
Set PYTHONPATH=C:\Program Files (x86)\QGIS Wien\apps\qgis\python  
eclipse.exe 
1
  • 1
    I think this is similar to the description inside A Quick Guide proposed before. But I still don't get the varibales correctly assigned. Mar 12, 2015 at 14:33
0

Relating to the error from your update, see the answer here if it helps. Sounds like a problem with a permanent entry for PYTHONPATH in your system variables.

0

you should add the path both PATH and PYTHONPATH. I had also this trouble before. Here is my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.