【问题标题】:How to add GDAL as a dependency to a Python package如何将 GDAL 作为依赖项添加到 Python 包
【发布时间】:2016-04-07 09:16:00
【问题描述】:

我正在尝试为使用 GDAL 的 PyPI 打包 Python 脚本。我首先在我的setup.py 中包含了直接引用:

install_requires=['GDAL==1.11.2'],

这样包在我的测试虚拟环境中安装失败:

extensions/gdal_wrap.cpp:2855:22: fatal error: cpl_port.h: No such file or directory
 #include "cpl_port.h"
                      ^
compilation terminated.
error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

然后我参考 pygdal 进行了尝试,因为它被标记为 virtualenv 友好版本:

install_requires=['pygdal'],

这样安装完成时不会出现错误(但通常会出现编译警告)。但是,当我调用脚本时,我得到了这个错误:

Traceback (most recent call last):
  File "/home/desouslu/.virtualenvs/test_p3/bin/hasc2gml", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 2716, in <module>
    working_set.require(__requires__)
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 685, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 588, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pygdal

将GDAL设置为依赖的正确方法是什么?

【问题讨论】:

    标签: python pip setuptools gdal


    【解决方案1】:

    经过各种测试,我得出结论这是pygdal 包本身的问题。正确声明了依赖项,但 pip 无法安装或编译它。我尝试在股票 Ubuntu 14.04 系统和 it fails 上直接安装 pygdalpip。目前还没有用于 GDAL/OGR 的 python 轮,这可能解释了这个问题。详情请参考this discussion

    我现在采用的策略是简单地将依赖项留给用户。在源代码中,这样的内容可以帮助用户:

    try:
        from osgeo import ogr
    except ImportError:
        raise (""" ERROR: Could not find the GDAL/OGR Python library bindings. 
                   On Debian based systems you can install it with this command:
                   apt install python-gdal""") 
    

    如果目标系统使用包管理机制(例如aptyum),则可以使用它而不是 PiPY 来分发依赖于 GDAL 的程序。

    【讨论】:

      猜你喜欢
      • 2015-03-29
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 2023-02-10
      • 1970-01-01
      • 2020-07-21
      • 2018-05-24
      • 1970-01-01
      相关资源
      最近更新 更多