Debug Python code in Eclipse-Debug Gdal_retile.py__python in FWTools2.4.7

Source: Internet
Author: User

debugging Python code in Eclipse

Gdal_retile.py is used to create a pyramid for remote sensing images, and I want to read the code in the program recently. A good way to read code is to step through it, but since you've never learned the Python language, you're not only unfamiliar with the language, but also ignorant of the development environment. Did not expect the first contact encountered a problem, for nearly two days before the debugging environment configuration successfully. I used to search for solutions on the Internet while solving the problem, but there was little value in the information, so I decided to share the experience for your reference.

After the FWTools2.4.7 installation is successful, running the Fwtools shell in the Start menu will eject the DOS window, in which you can execute the gdal_retile command, which actually executes the gdal_retile.bat, and the bat file is transferred Gdal_ retile.py. You will find that if you do not execute the command with the Fwtools Shell pop-up dos window, and instead open the DOS window separately, executing the Gdal_retile.bat in that window will fail because fwtools The Shell sets 6 important environment variables before opening the DOS window, respectively:

---------

Path=c:/progra~1/fwtool~1.7/bin; C:/progra~1/fwtool~1.7/python;

Set Pythonpath=c:/progra~1/fwtool~1.7/pymod

Set fwtools_dir=c:/progra~1/fwtool~1.7

Set Gdal_data=c:/progra~1/fwtool~1.7/data

Set Gdal_driver_path=c:/progra~1/fwtool~1.7/gdal_plugins

Set Geotiff_csv=c:/progra~1/fwtool~1.7/data

Set Proj_lib=c:/progra~1/fwtool~1.7/proj_lib

---------

Note that the installation location of FWTools2.4.7 using Python is "C:/Program Files/fwtools2.4.7/python", Its version is 2.3.4, and maybe your machine already has a different version of the Python interpreter, such as my machine, because of the ArcGIS software installed, my disk c:/python25 already has a 2.5 version of the interpreter. In order to be able to debug the Python program, I search the relevant information from the Internet, many people suggest using Pythonwin, so I installed the PythonWin2.5, the program by default and C:/python25 installed together.

An error occurred while opening fwtools2.4.7/bin/gdal_retile.py and stepping through the File menu in Pythonwin. The reason for the error is "Import gdal" error, import gdal will fwtools2.4.7/pymod/gdal.py 191 lines of code "import _gdal", the statement is intended to load fwtools2.4.7/pymod/_ Gdal.dll Library, but the debugger cannot find the path to the DLL library because of the PYTHONWIN environment variable settings. I tried to change the environment variable in the Pythonwin/tools/edit Python path menu, but I tried a variety of ways to end up not solving the problem.

Next, think over and over again, the reason for this error is either an environment variable setting issue or two different versions of Python that are causing the conflict. I have set the operating system's environment variables to add all six of these environment variables to the system environment variable, and the result is still unable to debug. Then I think I should change the development environment, the development environment should have two conditions: 1, you can set the location of the Python library, 2, you can set the environment variables that the program depends on. Finally found Pydev (http://pydev.org/index.html), download version 1.5.8 (Org.python.pydev.feature-1.5.8.2010062823.zip). I've never touched this tool before, it's an eclipse plugin. When you download it, add it to eclipse (how to add a plugin to ask Google).

After the successful installation of the Pydev plug-in, an extra "Pydev" was added to Eclipse's new project, select New Pydev project, and eject the wizard:

Click "Click here to configure a interpreter not listed" to configure the location and version of the Python interpreter as follows:

Create a new Python interpreter, named Python2.3.4, and then specify its position in C:/Program Files/fwtools2.4.7/python,eclipse automatically prompts C:/Program files/ Fwtools2.4.7/python/dlls, LIB, etc. added in. In addition to these directories, add a few directories. Click "New Folder" to add C:/Program Files/fwtools2.4.7/python/bin and C:/Program Files/fwtools2.4.7/python/proj_lib respectively.

Configuration to here, still cannot succeed import gdal, also need to configure environment variable. Also in this dialog box, click Environment, as shown below:

Click "New ..." to create an environment variable:

Name is: Path

Value is: c:/progra~1/fwtool~1.7/bin; C:/progra~1/fwtool~1.7/python;

Copy the c:/progra~1/fwtool~1.7/bin/gdal_retile.py to the SRC directory of the Eclipse project and press F11 to debug OK.

You can configure the startup parameters for the Python program, right-click gdal_retile.py to select Debug configurations in the Debug as menu pop-up:

parameter is

-levels 3-ps 512-co "Tiled=yes"-co "blockxsize=256"-co "blockysize=256"-co "Compress=jpeg"-co "JPEG_QUALITY=75" -s_srs epsg:4326-v-targetdir d:/temp d:/1.tif

The gdal_retile.py in the---debugging FWTools2.4.7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.