Skip to main content

Setting Up PyScripter for Quantum GIS

PyScripter is a general purpose Python Integrated Development Environment (IDE). Quantum GIS (QGIS) is a desktop GIS application that can be extended with Python plugins. Both are open source softwares. We intend to use PyScripter as an IDE to build QGIS Python plugin.

We are using PyScripter 2.4.1.0 and QGIS 1.6.0 in Windows.

PyScripter does not come with Python. On the other hand, QGIS is built in with Python. Thus, we will setup up PyScripter to use the build in Python in QGIS. We assume both PyScripter and QGIS are already installed.


Preparing PyScripter batch file

We assume that QGIS is installed in C:\OSGeo4W\ folder and PyScripter is installed in C:\Program Files\PyScripter\.

1. Copy qgis.bat in C:\OSGeo4W\bin to pyscripter.bat

2. Edit pyscripter.bat to remove the last line that read something like this

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

and replace it with this in one line

Start "PyScripter" /B "C:\Program Files\PyScripter\PyScripter.exe" --python25 --pythondllpath=C:\OSGeo4W\bin


Preparing PyScripter for Quantum GIS menu

We can just run pyscripter.bat file to open PyScripter. However, it will be convenient to have a PyScripter for QGIS menu in the Windows Start menu.

1. Click Start->All Programs->PyScripter
2. Right click on "PyScripter (Latest Python Version)" and copy.
3. Right click on "PyScripter" and paste.
4. Right click on "PyScripter (Latest Python Version) - Copy" and rename it to "PyScripter for Quantum GIS".
5. Right click on "PyScripter for Quantum GIS" and select Properties.
6. Change the Target to "C:\OSGeo4W\bin\pyscripter.bat"

Now we can start PyScripter by clicking on Start->All Programs->PyScripter->PyScripter for Quantum GIS.


Using Python from command prompt

QGIS Python command prompt can be accessed via PyScripter. Open the command prompt box from within PyScripter. Click on Tools->Tools->Command Prompt.





Comments

  1. Hello
    I am new to QGIS, Open Source and Python etc, though I have been working with ESRI since the age of floppies.
    I have QGIS 1.7.1-Wroclaw installed code Rev e6718b6
    I have Python Scripter installed 2.4.3.0

    I am trying to learn myPlugin Builder as per your Tutorial. However when I Copy and edit qgis.bat TO -> pyscripter.bat I FIND THE FILE EMPTY. Even the original qgis.bat is also empty. There is no last line like
    start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %*
    Kindly help - email is gisproo@gmail.com
    Thanks- Jazaak Allah

    ReplyDelete
  2. If you install QGIS using OSGeo4W Installer then the qgis.bat file will initialize OSGeo and QGIS dependencies such as Python, GRASS, GDAL, etc before starting QGIS. We want to do the same before we start PyScripter. The last line in qgis.bat is to start QGIS. We want to replace it with a command to start PyScripter that uses the python interpreter which is built-in with QGIS.

    If your qgis.bat is empty then just create an empty pyscripter.bat file and add this command in one line (do not split -- and pythondllpath):

    Start "PyScripter" /B "C:\Program Files\PyScripter\PyScripter.exe" --python25 --pythondllpath=C:\OSGeo4W\bin

    ...assuming that your PyScripter is installed in C:\Program Files\PyScripter\PyScripter.exe and your QGIS Python 2.5 interpreter is installed in C:\OSGeo4W\bin.

    ReplyDelete
  3. Hello Chelahmy

    Thanks for your help, but I am afraid I am far apart in my understanding

    I have corrected the pyscripter.bat and when I run this batch file from the E:\Program Files\Quantum GIS Wroclaw\bin

    IT OPENS THE PYSCRIPTER
    -------------------------------

    I have completed Installing Plugin Builder
    I have copied my plugin folder to C:\Documents and Settings\123\.qgis\python\plugins

    NOW I am not clear how to follow steps 2 - 8 under the heading of
    Generating QGIS Python plugin file set

    THANKS

    ReplyDelete
  4. Hi gisproo

    For step 2 and 3, please refer to Compiling our plugin in Getting Ready for Quantum GIS Plugin Development.

    Open the command prompt from within PyScripter - Tools->Tools->Command Prompt. Change directory to your plugin directory in qgis. And execute pyrcc4 and pyuic4 accordingly.

    And for step 4, please refer to Testing our plugin.

    For step 5 - 8, these are all python and qt programming.

    Use python console in qgis to experiment with qgis api.

    ReplyDelete
  5. Hello Chelahmy

    I have been able to do it, by figuring out my mistakes

    I have created 2 plugins and added them
    Thanks ... but

    How to activate a simple command like
    1) " Name of the 1st layer"
    2) " open table of 1st layer"

    Once again Thanks ... your post is very Good

    ReplyDelete
  6. Hi gisproo

    I'm glad that you managed to do it.

    Qgis api is the reference point.

    Here are some api calls to do what you want. Try them in python console on qgis:

    Get the first layer:

    >>> layer1 = QgsMapLayerRegistry.instance().mapLayers().values()[0]

    Get the name of the first layer:

    >>> layer1.name()

    Make the first layer active:

    >>> qgis.utils.iface.setActiveLayer(layer1)

    Open attribute table of the active layer:

    >>> qgis.utils.iface.actionOpenTable().activate(0)

    ReplyDelete
  7. Thanks Chelahmy

    I have been able to run the commands; though it took me some time to figure out as to what is "PYTHON CONSOLE" and from where to launch it.
    --------------------------------
    looking at API itself means deciphering a lot;I am not a professional programmer. About couple of years ago, I used to program a lot in Avenue in ArcGIS 3.x. I hope that with your help I will be able to do it.
    ---------------------------------

    I am thankful for your help
    Regards

    ReplyDelete
  8. Thank you for your hints, Chelahmy. Unfortunately, it doesn't work in my case. I've a USB-Stick with both QuantumGIS and Python27 plus PyScripter. The Stick shows two directories: OSGeo4W and PyScripter and i have to handle varying Drive Letters.

    So i tried the following: After copying PyScripter.ini from %APPDATA%/PyScripter to "MyStickDrive"\PyScripter, i deleted the first directory.
    Then i copied the OSGeo4W-Batch file and made changed it as followed:
    #####
    @echo on

    set DRV_LTR=%~d0
    set OSGEO4W_ROOT=%DRV_LTR%\OSGeo4W\

    call %OSGEO4W_ROOT%\bin\o4w_env.bat

    SET PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%OSGEO4W_ROOT%\apps\python27\lib;%OSGEO4W_ROOT%\apps\python27\lib\site-packages;%OSGEO4W_ROOT%\bin;%DRV_LTR%\PyScripter\Lib

    SET PATH=%OSGEO4W_ROOT%\bin;%PATH%

    SET PYTHONHOME=%OSGEO4W_ROOT%\bin

    start "PyScripter" /B %DRV_LTR%\PyScripter\PyScripter.exe --python27 --pythondllpath=%OSGEO4W_ROOT%\bin
    #####
    Maybe that some entries are unnecessary, they result from a try to use PythonWin as an simple IDE, coming with the OSGeo4W install.

    ReplyDelete

Post a Comment

Popular posts from this blog

Using React in Foundation for Sites

This post was the precursor to the Foundation-React Template . React and Foundation are two different web UI frameworks addressing different needs. They evolve differently. Both of them are powerful on their own accord. Fusing them together may create superpower. We will walk through the process of adding React into Foundation. We will start by installing both Foundation and React through command line interface (CLI). Then we will create a simple Todo web app. Along the way we will highlight the development process. But before all that, let us summarize React and Foundation. The details can be found at their respective websites. Both of them are well documented. React is a run-time UI rendering engine. It renders dynamic UI elements in its own fast virtual DOM, and only update necessary changes to the slow browser DOM. This behaves like a  double buffering DOM which makes any UI update feels fast. React wraps a UI rendering script in a component. A React component can ...

Debugging PHP using Apache Error Log

PHP runs on the server side and behaves like a function that return a value against the given arguments. A remote client may call this function and expect a specified return value and nothing else. So how do we debug this function ? It must not return debugging messages since the client is never designed to handle them. We must never burden any client to handle debugging messages. If we run PHP through Apache server then we can use the error log to keep our debugging messages. It may not be the best way to do it. But we only want to talk about this approach now. Error Logs The Apache error log files generally can be found in the following directory: var/log/apache2 We issue the following command from within the directory to read the latest error messages: # tail error.log The tail command reads the last few lines from the error.log file and prints them on the terminal. If we need to read a specific number of lines from the end of the file then we can specify the -n opti...