10

I'm new to Python. I want to create GIS app with Python using QGIS library on Window 7 64 bit.

The way I do:

install QGIS 1.7.0

  • I set PYTHONPATH=D:\Program Files (x86)\Quantum GIS Wroclaw\apps\qgis\python
  • I run python from cmd in D:\Program Files (x86)\Quantum GIS Wroclaw\bin
  • I type import qgis.core, a pop up window appear with text

The program can't start because qgis_core.dll is missing from your computer. Try reinstalling the program to fix this problem

and text in cmd is

ImportError: DLL load failed: The specified module could not be found.

Can anyone help me?

4

Reinstall QGIS with OSGeo4W installer, it has everything you need to develop already set up. http://trac.osgeo.org/osgeo4w/

5

You have to verify two things :

PYTHONPATH

The PYTHONPATH is set for the cmd you launch. This means that you have to set it globally on your system

Go to Control Panel -> System-> Advanced.

Click on the 'Environment Variables' button.

In the 'System Variables' panel that appears, click New and enter PYTHONPATH in the 'Variable Name' field. In the 'Variable Value' field enter the path to QGIS.

Or you can set it directly on the cmd command line just before launching the python interpreter with :

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

PATH

The DLL which will be used by the qgis python module must be in your path. Just as you set the PYTHONPATH above, set the PATH environment variable so that it contains the directory where qgis_core.dll is located.

The directory to add is probably D:\Program Files (x86)\Quantum GIS Wroclaw\apps\qgis But check that qgis_core.dll is really there.

OSGEO4W

As was suggested in another answer, OSGEO4W install and sets everything up for you. It will install another Python though, which can complicate things when you want to install third party Python modules not available in OSGEO4W.

You would as well get the latest QGIS version too, which is 1.7.4 (1.8 coming soon).

1

If you want to create a standalone application, you should use the copy qgis.bat in %OSGEO4W_ROOT%\bin as a template and replace the call to qgis with a call to python (or pythonw with your application script). You'll then have a python running in an environment similar to QGIS.

In other words: copy qgis.bat in D:\Program Files (x86)\Quantum GIS Wroclaw\bin to myqgisapp.bat and replace the last line in the copy

start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %*

with

start "My Quantum GIS App" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\pythonw.exe L:\path\to\your\python\app.py

Note: pythonw.exe will not open a separate text window, but print won't work (if you need that, use python.exe).

  • Thanks. But can you show me some step ? I'm so confused – newToAndroid Apr 5 '12 at 17:23
  • I dont have 15 reputation to vote your answer. Thank you anyway. :D – newToAndroid Apr 6 '12 at 0:45
0

Apart from Vincent's answer (which I found correct), it is important to note that the path to qgis_core.dll in the PATH environment variable should come first in the list.

Prior to finding this out, I have been stuck with the described problem in a QGIS 2.0.1 OSGeo4W installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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