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

MicroSD Card Module with SPI Connection

A MicroSD card can be directly connected to a 3.3v microcontroller without the need of any additional module. However, a cheap module such as shown in the picture above can be handy in terms of wiring and card replacement. Yet, if you get the module from China then you are on your own, you have to figure it out yourself how the module works. The module above needs 5v VCC to operate. The 5v is needed by the 3.3v LM1117 regulator to power the MicroSD card and the 74125 bus buffer (the 14-pin IC in the module above). Hence, the bus buffer is operating at 3.3v. The VCC is connected directly to the input of the regulator and no where else. Thus, the VCC is solely meant for the regulator. The right-side SPI bus (CS, SCK, MOSI & MISO) is connected directly to the 3.3v bus buffer. No line in the SPI bus that is connected to the VCC. Thus, the SPI bus does not follow VCC. The buffer is 5v tolerant so the right-side SPI connection can be driven at either 3.3v or 5v. Hence, the SPI ca

fatal: Couldn't find remote ref master

If you are using Github then  master is now known as main . Whatever you want to do with a master must now be referred to a main . If you search for this error message on the Internet then you will encounter with a lot of old discussions on how to set up your master properly which is probably not what you are looking for. The master  is your problem. Rename it to main . I wrote Git My Way about two years ago. Today I created another Github repository. I got this  "fatal: Couldn't find remote ref master"  error message when I wanted to sync the new repo for the first time with my notebook using the notes I wrote in the blog. All the discussions around the error message I found on the Internet were perplexing. Then I recalled that Github had renamed master to main  due to the master-slave connotation. We always have a master copy of a code, never a slave copy. Now suddenly a word context has been diminished for good. What is going to happen to the existing vast documen