Ubuntu16.04+Python2.7.12环境下用pip安装GDAL失败求助
Hey there, I’ve dealt with this exact GDAL installation headache on Ubuntu 16.04 with Python 2.7 before—let’s break down what’s going wrong and how to fix it.
First, a quick clarification: the osgeo package doesn’t exist as a standalone PyPI package—it’s part of the GDAL (Geospatial Data Abstraction Library) Python bindings. So installing the correct GDAL package will automatically give you access to osgeo.gdal and related modules like gdalconst.
The error you’re seeing (__main__.gdal_config_error: [Errno 2] No such file or directory) happens because pip can’t find the system-level GDAL development files it needs to build the Python bindings. Here’s how to fix it step by step:
Step 1: Install System-Level GDAL Dependencies
First, update your system packages and install the core GDAL libraries and development headers—these are mandatory for the Python package to build correctly:
sudo apt-get update sudo apt-get install gdal-bin libgdal-dev
Step 2: Match GDAL Versions (Critical!)
Pip’s GDAL package version must match the system-level GDAL version you just installed. First check your system’s GDAL version:
gdal-config --version
In your error log, you’re trying to install GDAL 2.2.3—so assuming your system now has that version, install the matching Python package. First, upgrade your outdated pip (you’re on 7.1.0, which can cause compatibility issues):
pip install --upgrade pip
Then install the matching GDAL version:
pip install GDAL==2.2.3
Step 3: Verify the Installation
Open a Python shell and test the imports to make sure everything works:
from osgeo import gdal from osgeo.gdalconst import *
If you don’t get any errors, you’re good to go!
Your Original Error Log for Reference
Collecting gdal
Using cached GDAL-2.2.3.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/GDAL.egg-info
writing pip-egg-info/GDAL.egg-info/PKG-INFO
writing top-level names to pip-egg-info/GDAL.egg-info/top_level.txt
writing dependency_links to pip-egg-info/GDAL.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/GDAL.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pycharm-packaging347/gdal/setup.py", line 339, in
**extra )
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py", line 180, in run
File "build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py", line 207, in find_sources
File "build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py", line 291, in run
File "build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py", line 320, in add_defaults
File "build/bdist.linux-x86_64/egg/setuptools/command/sdist.py", line 130, in add_defaults
File "/usr/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command
cmd_obj.ensure_finalized()
File "/usr/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/tmp/pycharm-packaging347/gdal/setup.py", line 214, in finalize_options
self.gdaldir = self.get_gdal_config('prefix')
File "/tmp/pycharm-packaging347/gdal/setup.py", line 188, in get_gdal_config
return fetch_config(option)
File "/tmp/pycharm-packaging347/gdal/setup.py", line 141, in fetch_config
raise gdal_config_error, e""")
File "", line 4, in
main.gdal_config_error: [Errno 2] No such file or directoryCommand "python setup.py egg_info" failed with error code 1 in /tmp/pycharm-packaging347/gdal/
You are using pip version 7.1.0, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
内容的提问来源于stack exchange,提问作者A.nechi

