1

I have installed gdal through anaconda. When I run a subprocess in Python before importing gdal I can get that gdal tools are located in my conda environment. For example subprocess.run(['which', 'gdal_rasterize']) would show /path/to/env/bin//gdal_rasterize

This is good because whenever I run gdal_rasterize within a subprocess it runs within the environment, however as soon as I import gdal into my Python interpreter or script (which I use gdal for other uses) whenever I run the same subprocess.run(['which' , 'gdal_rasterize']) I now get /usr/bin/gdal_rasterize

In fact importing gdal also changes the path to which version of Python I'm using in the environment. subprocess.run(['which', 'python']) changes to /usr/bin/python

This all wouldn't be an issue but I'm working on a server with tools that are less up to date than the conda environment and certain gdal functions have different parameters. Just trying to figure out why the environment would be changed for some reason.

Does anyone have any ideas?

I am on Linux (CentOS 6.6)

  • 1
    Are you using Ipython? spyder? I am wondering: would sys.path change after the import? Have you tried re-installing a clean environment? Working on a unix server as well I have a gdal environment that I don't ever touch after breaking it several times just by installing something new. gdal has a buggy implementation with conda (and python in general). I guess that if the gdal version has some compatibility issues it may force the interpreter to switch to another python in the system (that should show up in the path). – Andrea Massetti Mar 13 at 10:56
  • I am having the same issue too. Importing gdal in jupyter notebook switches my python from anaconda to root python. I am using Mac, macOS Mojave 10.14.6 – snookrun Jul 30 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.