64-bit Mapscript for Python on Windows

date:2010-08-03 10:17
author:admin
category:mapserver, python
tags:64bit, gdal
slug:64-bit-mapscript-for-python-on-windows
status:published

Tamas Szekeres maintains a site with many different compiled versions of MapServer at http://vbkto.dyndns.org/sdk/ (the site can occasionally be overloaded or down). These are compiled daily direct from the source. It is a veritable Aladdin’s cave of treasures ?” especially if you are installing on a Windows Server, and even more so if you are installing for 64bit.

It gets even better though! Included in the installation are the latest SQL Server 2008 driver, 64 bit GDAL, and MapScript Python bindings. MapScript allows MapServer functions and classes to be scripted in a variety of languages.

As Python is becoming ubiquitous in the GIS world (opensource and proprietary), if you aren’t familiar with PHP then You can download the zip file and extract to a folder on your machine, in the example below I used C:\ms4w64 (old habits die hard!).

Install Steps

1. Add C:\ms4w64\bin to your system PATH environment variable (right-click on My Computer, select Properties, Advanced, Environment Variables, then in System Variables select PATH and edit. Remember to put a semi-colon ; between folders in the path.

image

Adding this folder to your PATH will allow Windows to find the MapServer and GDAL DLLs used by Mapscript.

2. Now we want to make the Mapscript Python module available in Python. There are a couple of options here. I took the files from C:\ms4w64\bin\ms\python and copied them into C:\Python26\Lib\site-packages ?” the default search location for third party Python modules. The files to copy across are:

  • _mapscript.pyd
  • mapscript.py
  • A mapscript.pyc (compiled Python) file will be generated on first use

Alternatively you can add the C:\ms4w64\bin\ms\python folder to the PYTHONPATH Window’s environment variable as in step 1.

Important! You will need to log off, or restart your PC in order for the environment variables to be “refreshed” by the operating system.

Either way you should now be able to type “import mapscript” in IDLE without receiving errors.

image

Errors?

[python]Traceback (most recent call last):
File “<pyshell#0>”, line 1, in <module>
import mapscript
ImportError: No module named mapscript[/python]

Python can’t find the Mapscript module. Try typing the following commands into Idle to see the folders that Python checks looking for modules:

[python]import sys
print sys.path[/python]

image

[python]Traceback (most recent call last):
File “<pyshell#13>”, line 1, in <module>
import mapscript
File “C:\Python25\lib\site-packages\mapscript.py”, line 28, in

<module> | import _mapscript | ImportError: DLL load failed with error code 193[/python]

It is likely you are using a 32 bit version of Python with 64 bit versions of the MapServer DLLs. You may have reinstalled and reconfigured Python so many times that you have actually forgotten what you installed. A useful program in this case can be downloaded from http://www.mitec.cz/exe.html

This tells you the processor type for a .exe file such as python.exe. Check that it is a 64-bit version as shown below.

image

orphan:

Comments

http://www.gravatar.com/avatar/?s=55&d=identicon&r=g

1. Setting up a Secure Cascading WMS on MapServer at geographika **

[...] site installed in a C:ms4w64 folder. It also assumes MapServer has been configured with SSL as detailed in another post. In this example I use IIS and Windows Server [...]

Reply
http://www.gravatar.com/avatar/a6fe46b153b38f38c4aeb24ce372e041?s=55&d=identicon&r=g

2. Mei **

hi there!
could you please post your compiled 64 bit curl with ssl on this

site..? | really need to download it, thanks..

Reply
http://www.gravatar.com/avatar/ec399a4765f732e1a2acd5ca7edd0fd5?s=55&d=identicon&r=g

3. geographika **

Hi - I’ve put the x64 DLL at http://bitbucket.org/geographika/mapserver-scripts/src/tip/cURL/

Reply
http://www.gravatar.com/avatar/4b755cf7a74e38d05963c959a1ac804c?s=55&d=identicon&r=g

4. Tobias **

Hi,
I tried your dll! It works but only for web pages with no special

encoding. If you have a page with curl_easy_setopt(cUrl, CURLOPT_ENCODING, “gzip”); it only returns junk! Is zlib included / linked? Could you please upload a dll with zlib included?

Thanks

Reply
http://www.gravatar.com/avatar/ec399a4765f732e1a2acd5ca7edd0fd5?s=55&d=identicon&r=g

5. geographika **

Hi Tobias,

It appears there is now a compiled version of cURL with (and without) SSL available on the download page at http://curl.haxx.se/download.html

Maybe give this a try to see if it includes zlib. Let us know the outcome!

Reply
http://www.gravatar.com/avatar/4b755cf7a74e38d05963c959a1ac804c?s=55&d=identicon&r=g

6. Tobias **

Hi geographika,

at haxx there are only binary files for windows x64 (curl.exe) but I need a dll for my app. I can complile a x64 lib to include in my project and to satisfy the compiler but the dll compiled with this lib has no sll and no zlib. So when accessing SSL or compressed pages, I only get encypred data. For the 32bit version I only have to replace the libcurl.dll and so I intend to do with the 64bit version, too.

Thanks

Reply
http://www.gravatar.com/avatar/4b755cf7a74e38d05963c959a1ac804c?s=55&d=identicon&r=g

7. Tobias **

Hi,

I made a compile with all components including zlib and libssh2. Now everything works fine! Your tutorial helped to get the compile running!

Greetings!

Reply
http://www.gravatar.com/avatar/4ecc4ba60d49afcb8b7da90d23b9eb15?s=55&d=identicon&r=g

8. thierry **

Hi,
Could you put these x64 builds (dll, lib) somewhere I can download ?
Reply
Add Comment