如何使用pip在python 2.7.12中使用Ubuntu 16,04安装GDAL?

时间:2018-01-09 14:14:48

标签: python pip gdal

我正在尝试使用python导入一些特定的库。它应该像导入numpy一样容易,例如:

import osgeo.gdal, gdal
from osgeo.gdalconst import *

但在我看来,gdal和osgeo包都丢失了所以我去项目解释器添加这些包,可悲的是我没有找到包osgeo并且无法安装包gdal ...我看了在网上,但似乎没有确切的方法来解决这个问题。

我正在使用Ubuntu 16,04和python 2.7.12 PS GDAL是地理空间数据抽象库

这是我收到的错误消息:

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 "<string>", line 1, in <module>
  File "/tmp/pycharm-packaging347/gdal/setup.py", line 339, in <module>
    **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 "<string>", line 4, in <module>
__main__.gdal_config_error: [Errno 2] No such file or directory

----------------------------------------

 Command "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.

1 个答案:

答案 0 :(得分:1)

最后我找到了解决问题的方法。

sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin
sudo apt-get -y install python-gdal

谢谢大家的贡献。