Python GDAL:pip安装--no-install GDAL失败

8

我正在尝试在基于虚拟环境中安装GDAL,根据各种解决方案

然而,下载本身已经失败:

$ pip install --no-install GDAL

以下是 pip.log 日志:

------------------------------------------------------------
/Users/test/venv/bin/pip run on Sun Jun  2 15:35:15 2013
Downloading/unpacking GDAL

  Running setup.py egg_info for package GDAL

    running 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
    warning: manifest_maker: standard file '-c' not found


    Traceback (most recent call last):

      File "<string>", line 16, in <module>

      File "/Users/test/venv/build/GDAL/setup.py", line 267, in <module>

        ext_modules = ext_modules )

      File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup

        dist.run_commands()

      File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands

        self.run_command(cmd)

      File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

        cmd_obj.run()

      File "<string>", line 14, in replacement_run

      File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/egg_info.py", line 259, in find_sources

        mm.run()

      File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/egg_info.py", line 325, in run

        self.add_defaults()

      File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/egg_info.py", line 361, in add_defaults

        sdist.add_defaults(self)

      File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/sdist.py", line 211, in add_defaults

        build_ext = self.get_finalized_command('build_ext')

      File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command

        cmd_obj.ensure_finalized()

      File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized

        self.finalize_options()

      File "/Users/test/venv/build/GDAL/setup.py", line 164, in finalize_options

        self.gdaldir = self.get_gdal_config('prefix')

      File "/Users/test/venv/build/GDAL/setup.py", line 144, in get_gdal_config

        return fetch_config(option)

      File "/Users/test/venv/build/GDAL/setup.py", line 97, 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

    Complete output from command python setup.py egg_info:

    running 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

warning: manifest_maker: standard file '-c' not found



Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/Users/test/venv/build/GDAL/setup.py", line 267, in <module>

    ext_modules = ext_modules )

  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup

    dist.run_commands()

  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "<string>", line 14, in replacement_run

  File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/egg_info.py", line 259, in find_sources

    mm.run()

  File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/egg_info.py", line 325, in run

    self.add_defaults()

  File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/egg_info.py", line 361, in add_defaults

    sdist.add_defaults(self)

  File "/Users/test/venv/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/setuptools/command/sdist.py", line 211, in add_defaults

    build_ext = self.get_finalized_command('build_ext')

  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command

    cmd_obj.ensure_finalized()

  File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized

    self.finalize_options()

  File "/Users/test/venv/build/GDAL/setup.py", line 164, in finalize_options

    self.gdaldir = self.get_gdal_config('prefix')

  File "/Users/test/venv/build/GDAL/setup.py", line 144, in get_gdal_config

    return fetch_config(option)

  File "/Users/test/venv/build/GDAL/setup.py", line 97, 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 /Users/test/venv/build/GDAL

Exception information:
Traceback (most recent call last):
  File "/Users/test/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py", line 139, in main
    status = self.run(options, args)
  File "/Users/test/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py", line 266, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Users/test/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1057, in prepare_files
    req_to_install.run_egg_info()
  File "/Users/test/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 236, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/Users/test/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/util.py", line 662, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in /Users/test/venv/build/GDAL

我错过了什么?


对我有帮助的收据来自 https://stackoverflow.com/questions/51353962/pip3-gdal-install-failed-on-command-python-setup-py-egg-info-failed-with-error/52245969#52245969 - Ryabchenko Alexander
3个回答

13

@user1738154提供的解决方法对我来说没有按预期工作,所以我选择使用HomeBrew安装GDAL,然后在我的虚拟环境中使用pip。

    $ brew install gdal
    (venv)$ pip install GDAL

所有的代码都编译通过,并成功运行。


1
这个非常好用,谢谢!请确保执行“brew update”,因为最新的GDAL配方中lzip包已从1.14升级到1.15。 - jatal

6
解决该问题的方法是:
  1. 此网站下载GDAL Complete
  2. 安装GDAL Complete.pkg
  3. 进入/Library/Frameworks/GDAL.framework/Versions/1.10/并拷贝所有文件
  4. 进入您的虚拟环境的sites-packages /venv/lib/python2.7/site-packages,并将拷贝的文件粘贴到其中

谢谢!运行得非常完美! - rebelliard
所以确认一下,GDAL文件必须存储在为特定脚本选择的解释器的目录中吗?例如,如果我使用的解释器用于运行脚本,则保存在〜\AppData\Local\Programs\Python\Python310\python.exe中,那么我应该把GDAL文件放在哪里?我对这一切如何工作感到很模糊,所以如果这不是一个聪明的问题,我很抱歉。 - Max Duso

1
在主机上按照以下步骤安装gdal之后:

sudo apt-get install gdal-bin
sudo apt-get install libgdal-dev

之后使用
pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal"

这应该能像魔法一样运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接