You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Red Hat EL7.3集群中Python3.5导入gdal_array失败问题求助

Fixing gdal_array Import Error with GDAL 2.2.4 on Red Hat EL 7.3

Hey there, I’ve run into this exact issue before with older GDAL versions on RHEL systems. Let’s break down what’s going on and how to fix it.

Your Setup & Error Details

You’re running Red Hat EL 7.3 with GDAL 2.2.4 and Python 3.5. You can successfully import gdal, osgeo, and osr, but importing gdal_array throws an error. Your code and truncated traceback look like this:

import gdal
import osgeo
import osr
from osgeo import gdal_array
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/.local/lib/python3.5/site-packages/osgeo/gdal_array.py", line 28, in <module>
    _gdal_array = swig_import_helper()
  File "/.local/lib/python3.5/site-packages/osgeo/gdal_array.py", line 24, in swig_import_helper
    _mod = imp.load_module('_gdal_array', fp, pathname, description)
  File "/usr/lib64/python3.5/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib64/python3.5/imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: libgdal.so.20: cannot open shared object file: No such file or directory

(Note: The full error almost always points to a missing shared library or mismatched Python bindings)

Solutions to Try

  • Fix the Shared Library Path
    The most common culprit is that your system can’t locate the GDAL shared library. First, find where libgdal.so.20 lives:

    find / -name libgdal.so.20 2>/dev/null
    

    Once you get the path (e.g., /usr/local/lib), add it to your library path temporarily:

    export LD_LIBRARY_PATH=/path/to/gdal/lib:$LD_LIBRARY_PATH
    

    To make this change permanent, add that line to your ~/.bashrc or ~/.bash_profile and log back in to apply it.

  • Recompile GDAL with Python & Array Bindings
    If you installed GDAL from source, you might have skipped enabling the Python array bindings. First, install required dependencies:

    yum install python35-devel numpy
    

    Then recompile GDAL with the correct flags:

    ./configure --with-python --enable-shared
    make clean && make && make install
    

    After compiling, navigate to the swig/python directory in the GDAL source and install the Python bindings properly:

    cd swig/python
    python3 setup.py install
    
  • Align Python GDAL Package with System GDAL
    Sometimes the GDAL Python package installed via pip doesn’t match your system’s GDAL version. Uninstall the existing package first:

    pip3 uninstall gdal
    

    Then install the exact version matching your system’s GDAL:

    pip3 install gdal==2.2.4
    
  • Try Alternative Import Syntax
    Older GDAL versions sometimes use different import paths for gdal_array. Give these alternatives a shot:

    import gdal_array
    

    Or:

    from osgeo.gdal_array import *
    

内容的提问来源于stack exchange,提问作者Chris G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:13:48