<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>Glad it's working for you, and good to know it can work alongside QGIS. <br></div><div>The GISInternal Python MapScripts I think are built with SWIG 2.0, whereas I compiled those wheels with the latest version of SWIG 4.0.2/master build. That may explain why the GISInternals don't work with more recent Python versions. <br></div><div><br>Seth<br></div><div><br></div><div id="sig62266145"><div class="signature">--<br></div><div class="signature">web:<a href="https://geographika.net">https://geographika.net</a><br></div><div class="signature">twitter: @geographika<br></div></div><div><br></div><div><br></div><div>On Mon, May 2, 2022, at 3:38 PM, maëlle lapriel wrote:<br></div><blockquote type="cite" id="qt" style=""><div dir="ltr"><div>Hi Seth,<br></div><div><br></div><div>It is working fine with Python 3.6 and the corresponding GISInternals build until I try it in a venv, however it's not working on any other Python version (and matching GISInternals) regardless of venv or not. Regarding venv and env variables, it doesn't seem that anything gets wiped when activating a venv.<br></div><div><br></div><div>Interestingly, I got it working on all tested Python versions (3.6, 3.7, 3.9) by installing MapScript using your wheels instead of using the MapScript that ships with MapServer, both in venv and outside, and together with QGIS loaded. I have no idea what exactly the difference is ultimately, but at least I have a working environment now, so many thanks!<br></div></div><div><br></div><div class="qt-gmail_quote"><div dir="ltr" class="qt-gmail_attr">On Fri, 29 Apr 2022 at 10:15, Seth G <<a href="mailto:sethg@geographika.co.uk">sethg@geographika.co.uk</a>> wrote:<br></div><blockquote class="qt-gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-color:rgb(204, 204, 204);border-left-style:solid;border-left-width:1px;padding-left:1ex;"><div><u></u><br></div><div><div>Hi,<br></div><div><br></div><div>As you wrote, the version of Python needs to match the version of Python used by GISInternals (which is different dependent on the package) e.g. <a href="https://www.gisinternals.com/packageinfo.php?file=release-1928-x64-gdal-3-4-2-mapserver-7-6-4.zip" target="_blank">https://www.gisinternals.com/packageinfo.php?file=release-1928-x64-gdal-3-4-2-mapserver-7-6-4.zip</a> - "python - Python37-AMD64"<br></div><div><br></div><div>Is everything working fine until you setup a virtual environment? This could be because activating a Python virtual environment on Windows seems to wipe out any previously set environment variables in the session. Try activating the virtual environment, and then running SDKShell.bat (or simply setting the environment variables you need from that file).<br></div><div><br></div><div>SET PATH=C:\MapServer\bin;%PATH%<br></div><div>SET PROJ_LIB=C:\MapServer\proj7\SHARE<br></div><div>SET MAPSERVER_DLL_PATH=C:\MapServer\bin<br></div><div><br></div><div>I have some experimental MapScript Wheels [1] built for various versions of Python with a recent MapServer development build, which could work with a <span>release-1930-x64 development build [2]. </span><br></div><div><span></span><br></div><div>Seth<br></div><div><br></div><div>[1] <a href="https://github.com/geographika/python-mapscript/tree/main/wheels" target="_blank">https://github.com/geographika/python-mapscript/tree/main/wheels</a><br></div><div>[2] <a href="https://www.gisinternals.com/query.html?content=filelist&file=release-1930-x64-gdal-mapserver.zip" target="_blank">https://www.gisinternals.com/query.html?content=filelist&file=release-1930-x64-gdal-mapserver.zip</a><br></div><div id="qt-gmail-m_7892287460302850105sig62266145"><div>--<br></div><div>web:<a href="https://geographika.net" target="_blank">https://geographika.net</a><br></div><div>twitter: @geographika<br></div></div><div><br></div><div><br></div><div>On Fri, Apr 29, 2022, at 9:08 AM, maëlle lapriel wrote:<br></div><blockquote type="cite" id="qt-gmail-m_7892287460302850105qt"><div dir="ltr"><div dir="ltr"><div dir="auto"><div>Hi Seth,<br></div><div dir="auto"><br></div><div dir="auto">I've considered this to be the problem, however I can rule out any dependency conflicts already since I also tried to simply just get MapScript running in a Python env without any other imports.<br></div><div dir="auto">Am I assuming right that for just using MapScript alone, I can just run the SDKShell.bat to have all the variables set, then take a Python version that matches the GISInternals build and I'm good to go? Because that already yields mentioned import errors, with every possible build or Python version except 3.6 and MapServer 7.6.1, which also stops working as soon as I set up a venv. <br></div><div dir="auto"><br></div><div dir="auto">Thank you very much for your help.<br></div><div dir="auto"><br></div><div dir="auto"><div>Cheers<br></div><div><br></div><div dir="auto"><div dir="ltr">On Thu, Apr 28, 2022, 18:25 Seth G <<a href="mailto:sethg@geographika.co.uk" target="_blank">sethg@geographika.co.uk</a>> wrote:<br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-color:rgb(204, 204, 204);border-left-style:solid;border-left-width:1px;padding-left:1ex;"><div><u></u><br></div><div><div>Hi Maëlle,<br></div><div><br></div><div>MapScript (and MapServer) use many of the same dependent DLLs as QGIS - GDAL, Proj, GEOS etc. which would then get loaded into memory by Python. <br></div><div>For everything to work correctly, all these dependencies would have to be the same version, and (I think this is still the case), compiled with the same version of Microsoft Visual C (the 1928, 1931 etc. use when naming the GISInternals zips). <br></div><div>It probably would be possible to get everything build and working, but you'd likely have to compile everything yourself. <br></div><div>Is it possible to modify your workflow so a PyQGIS environment dumps out data to disk and then a MapScript environment works on this data? <br></div><div>I'd imagine PyQGIS can probably do everything MapScript can, except for manipulate Mapfiles - you could take a look at mappyfile for this, which is Python only has has no dependent DLLs.<br></div><div><br></div><div>Seth<br></div><div><br></div><div id="qt-gmail-m_7892287460302850105qt-gmail-m_-8314549521591085881m_-3877145255547645885sig62266145"><div>--<br></div><div>web:<a href="https://geographika.net" rel="noreferrer" target="_blank">https://geographika.net</a><br></div><div>twitter: @geographika<br></div></div><div><br></div><div><br></div><div>On Thu, Apr 28, 2022, at 11:42 AM, maëlle lapriel wrote:<br></div><blockquote type="cite" id="qt-gmail-m_7892287460302850105qt-gmail-m_-8314549521591085881m_-3877145255547645885qt"><div dir="ltr"><div dir="ltr"><div dir="ltr">I'm trying to write a PyQGIS standalone script which utilizes MapScript for certain tasks. In a first attempt, I basically did this:<br></div><div dir="ltr"><br></div><div>- I installed MapScript globally with pip and using the Python 3.9.5 interpreter which ships with QGIS 3.22.6 (also includes wheel)<br></div><div>- Created a venv with --system-site-packages<br></div><div>- Downloaded the appropriate Windows binary build of MapServer from GISInternals (release-1928-x64-gdal-3-4-mapserver-7-6) and extracted into C:\MapServer\<br></div><div>- Set the MAPSERVER_DLL_PATH to C:\MapServer\bin<br></div><div dir="ltr"><br></div><div>However, whenever I try to load MapScript, it yields the following:<br></div><div><br></div><div><div>Traceback (most recent call last):<br></div><div> File "<string>", line 1, in <module><br></div><div> File "C:\QGIS\apps\Python39\lib\site-packages\mapscript\__init__.py", line 2, in <module><br></div><div> from .mapscript import *<br></div><div> File "C:\QGIS\apps\Python39\lib\site-packages\mapscript\mapscript.py", line 13, in <module><br></div><div> from . import _mapscript<br></div><div>ImportError: DLL load failed while importing _mapscript: The specified module could not be found.<br></div></div><div><br></div><div>As to where the README over at github indicates that this means MapServer.dll can't be found.<br></div><div><br></div><div>In order to rule out possible issues, I also tried the following:<br></div><div><br></div><div>- Not creating a venv, but using it with the QGIS python version directly<br></div><div>- Installing MapScript into normal installations of python 3.7, 3.8, 3.9, 3.10<br></div><div>- Using it together with the latest builds of MapServer (1930)<br></div><div>- Not installing MapScript with pip but copying over mapscript.py and _mapscript.pyd from the respective MapServer builds<br></div><div>- Adding C:\MapServer\bin to PATH instead of the new env variable<br></div><div><br></div><div>All with the same result. The only ever combination I got it working is when installing the MapScript globally using python3.6/pip and the old MapServer release-1911 (7.6.1), where I sadly can't import PyQGIS in the version I need.<br></div><div><br></div><div>What could be the issue here? <br></div><div><br></div><div>Kind regards, Maëlle<br></div></div></div><div>_______________________________________________<br></div><div>MapServer-users mailing list<br></div><div><a href="mailto:MapServer-users@lists.osgeo.org" rel="noreferrer" target="_blank">MapServer-users@lists.osgeo.org</a><br></div><div><a href="https://lists.osgeo.org/mailman/listinfo/mapserver-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/mapserver-users</a><br></div><div><br></div></blockquote><div><br></div></div></blockquote></div></div></div></div></div></blockquote><div><br></div></div></blockquote></div></blockquote><div><br></div></body></html>