1

I use QGIS and therefore also OSGeo4W.
At the moment I am writing a script that use ogr in python. I need a virtual environment for because it is going to be deployed on a server (which also has OSGeo4W). After creating a virtual env (python -m venv venv) then I cannot import ogr as I would do from the OSGeo4W shell from osgeo import ogr. I am a windows user, so is the server.

I have been reading many post about issues using/installing ogr in python but at the moment I am completely confused, I . I am not a very experienced python user, and setting up the dependencies appear to be the hardest bit yet. This post is similar to what I want to do Use OGR and GDAL in Python outside OSGEO4W shell but the link in the post to binaries include mapserver which I am not interested in. Any advice?

6
  • 3
    Despite the name of the directory you can install just GDAL. For example this GDAL core installer installs just GDAL core features download.gisinternals.com/sdk/downloads/…. But if you download some other package that contains also MapServer binaries then just don't run MapServer.
    – user30184
    Dec 3, 2019 at 15:35
  • I use QGIS and therefore also OSGeo4W. therefore also doesn't necessarily follow, you don't need OSGeo4W to use QGIS.
    – nmtoken
    Dec 3, 2019 at 16:50
  • That is true, I just wanted to point out that I am aware that using OSGeo4W is an option, was thinking maybe I can "reuse" ogr that come with OSGeo4W in my python env. But as far as I can tell, that is not possible.
    – geogrow
    Dec 4, 2019 at 7:37
  • @user30184 I installed the suggested download and I can now run ogr from cmd. But I can still not use it in my "regular" python or python in my created venv. Am I misunderstanding the use of it or is it still not working? I have tried import ogr and from osgeo import ogr. Giving me ModuleNotFoundError: No module named 'osgeo' or ModuleNotFoundError: No module named 'ogr'
    – geogrow
    Dec 4, 2019 at 7:42
  • You must also install the GDAL Python bindings from the same download page. There is also a note on that page Note: In order to have the bindings work the location of the core components must be included manually in the PATH environment variable.. Unfortunately I do not know what those core components are.
    – user30184
    Dec 4, 2019 at 8:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.