# How to import qgis.core to python app?

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

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. Thank in advance.

-

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

-
Thank you very much. –  newToAndroid Apr 5 '12 at 10:18

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).

-
I've done, thank you very much –  newToAndroid Apr 5 '12 at 9:59
You should accept my answer then : meta.stackoverflow.com/questions/5234/… –  Vincent Apr 5 '12 at 12:14

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