Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import gdal clobbering PATH environment variable on Ubuntu #1231

Closed
Thingus opened this issue Jan 24, 2019 · 6 comments
Closed

import gdal clobbering PATH environment variable on Ubuntu #1231

Thingus opened this issue Jan 24, 2019 · 6 comments

Comments

@Thingus
Copy link

Thingus commented Jan 24, 2019

Problem description

On import, gdal prepends "[env]\Library\bin;" to PATH, breaking any subprocesses that depend on that path.

Steps to reproduce the problem.

>>> import os
>>> os.environ["PATH"]
'/home/john/miniconda3/envs/eoenv/bin:/home/john/miniconda3/bin:....'
>>> import gdal
>>> os.environ["PATH"]
'/home/john/miniconda3/envs/eoenv\\Library\\bin;/home/john/miniconda3/envs/eoenv/bin:/home/john/miniconda3/bin...'
>>> 

Operating system

Ubuntu 18.04 64 bit

GDAL version and provenance

GDAL 2.3.3 version from from conda ( py36hbb2a789_0)
Python 3.6.8

@Thingus
Copy link
Author

Thingus commented Jan 24, 2019

Workaround:

import gdal
os.environ["PATH"] = os.environ["PATH"].split(';')[1]

@rcoup
Copy link
Member

rcoup commented Jan 24, 2019

@Thingus I can't find anything that sets PATH in the codebase, either via os.environ or setenv()/putenv()

This is under master (via the Trusty/Linux vagrant dev environment):

vagrant@gdal-vagrant:~$ python
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['PATH']
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'
>>> import gdal
>>> os.environ['PATH']
'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'
>>> gdal.VersionInfo()
'2050000'

This is under 2.3.x on another Ubuntu host:

$ ipython
Python 2.7.6 (default, Nov 13 2018, 12:45:42)
Type "copyright", "credits" or "license" for more information.

IPython 1.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import os

In [2]: os.environ['PATH']
Out[2]: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin'

In [3]: import gdal

In [4]: os.environ['PATH']
Out[4]: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin'

In [5]: gdal.VersionInfo()
Out[5]: '2030200'

That would suggest it's something anaconda-related?

@rouault
Copy link
Member

rouault commented Jan 24, 2019

Neither the GDAL library nor the Python bindings of upstream GDAL touch the PATH. Must be something anaconda-related indeed. Should be reported to their bug tracker.

@ensafi
Copy link

ensafi commented Mar 23, 2019

Neither the GDAL library nor the Python bindings of upstream GDAL touch the PATH. Must be something anaconda-related indeed. Should be reported to their bug tracker.

Are there different versions of GDAL out there? The GDAL 2.3.2 Python bindings (using Python 3.6 under Anaconda3) has an "osgeo/__init__.py" that starts as follows and does indeed modify PATH:

# __init__ for osgeo package.

# making the osgeo package version the same as the gdal version:
import os
import sys
if not '%s\Library\bin' % (sys.prefix) in os.environ['PATH']:
    os.environ['PATH'] = r'%s\Library\bin;%s' % (sys.prefix, os.environ['PATH'])

Notice that it simply appends "\Library\bin;" to the PATH entry matching sys.prefix, without checking to see if the host system is Windows.

@rouault
Copy link
Member

rouault commented Mar 23, 2019

This is not the content of the official file provided by GDAL: https://github.com/OSGeo/gdal/blob/master/gdal/swig/python/osgeo/__init__.py

@ensafi
Copy link

ensafi commented Mar 23, 2019

Thank you, I see that now, and I have reported it to the Anaconda team. Looks like distribute patched versions of libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants