在为Python安装GDAL时遇到问题 [英] Having trouble installing GDAL for python

查看:681
本文介绍了在为Python安装GDAL时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说,我已经寻求帮助来解决这个问题,并经历了许多发现的问题,但没有一个起作用,或者我无法理解他们在说什么. /p>

此类线程位于此处: Python GDAL软件包通过pip安装时缺少头文件

我能够跑步

pip install --no-install GDAL

但是随后我被指示"cd进入ENV/build/GDAL".我知道cd的含义,但我不知道此/ENV/build/GDAL目录的位置,并且在帖子中或在它引用的帖子中没有关于它的更多信息.

核心问题只是我要安装GDAL以在Python中使用.我尝试过

pip安装GDAL,但输出失败:

    Collecting GDAL
  Using cached GDAL-2.0.1.tar.gz
Installing collected packages: GDAL
  Running setup.py install for GDAL
    Complete output from command c:\users\isaac\appdata\local\programs\python\python35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Isaac\\AppData\\Local\\Temp\\pip-build-4kmkv1_4\\GDAL\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Isaac\AppData\Local\Temp\pip-fxko2gfx-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.5
    copying gdal.py -> build\lib.win32-3.5
    copying ogr.py -> build\lib.win32-3.5
    copying osr.py -> build\lib.win32-3.5
    copying gdalconst.py -> build\lib.win32-3.5
    creating build\lib.win32-3.5\osgeo
    copying osgeo\gdal.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdalconst.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdalnumeric.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdal_array.py -> build\lib.win32-3.5\osgeo
    copying osgeo\ogr.py -> build\lib.win32-3.5\osgeo
    copying osgeo\osr.py -> build\lib.win32-3.5\osgeo
    copying osgeo\__init__.py -> build\lib.win32-3.5\osgeo
    Fixing build\lib.win32-3.5\gdal.py build\lib.win32-3.5\ogr.py build\lib.win32-3.5\osr.py build\lib.win32-3.5\gdalconst.py build\lib.win32-3.5\osgeo\gdal.py build\lib.win32-3.5\osgeo\gdalconst.py build\lib.win32-3.5\osgeo\gdalnumeric.py build\lib.win32-3.5\osgeo\gdal_array.py build\lib.win32-3.5\osgeo\ogr.py build\lib.win32-3.5\osgeo\osr.py build\lib.win32-3.5\osgeo\__init__.py
    Skipping optional fixer: ws_comma
    Fixing build\lib.win32-3.5\gdal.py build\lib.win32-3.5\ogr.py build\lib.win32-3.5\osr.py build\lib.win32-3.5\gdalconst.py build\lib.win32-3.5\osgeo\gdal.py build\lib.win32-3.5\osgeo\gdalconst.py build\lib.win32-3.5\osgeo\gdalnumeric.py build\lib.win32-3.5\osgeo\gdal_array.py build\lib.win32-3.5\osgeo\ogr.py build\lib.win32-3.5\osgeo\osr.py build\lib.win32-3.5\osgeo\__init__.py
    Skipping optional fixer: ws_comma
    running build_ext
    building 'osgeo._gdal' extension
    error: [WinError 2] The system cannot find the file specified

Command "c:\users\isaac\appdata\local\programs\python\python35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Isaac\\AppData\\Local\\Temp\\pip-build-07o7k41s\\gdal\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Isaac\AppData\Local\Temp\pip-640gw1ah-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Isaac\AppData\Local\Temp\pip-build-07o7k41s\gdal

有人可以帮我吗?我完全迷路了,不知道该怎么办.

我想知道是否是因为我的python安装在一个有趣的地方?它安装在C:\ Users \ Isaac \ AppData \ Local \ Programs \ Python \ Python35-32 \上,这是我安装PyCharm时放置的位置,但是该文件夹和其中的/Scripts/文件夹位于我的PATH中. /p>

经过更多研究,我想知道是否是因为我使用的是Python 3.5?我将尝试回滚到Python 3.4,看看它是否有任何改变

不,没有运气,它仍然失败并告诉我

error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat)

我尝试安装Microsoft Visual C ++ 10.0,它只是告诉我我的计算机上已经有较新的版本.

解决方案

安装此类库的最简单方法可能是conda.以用户(不是root)的身份获取并安装 Miniconda .现在,创建一个新环境并将gdal安装到其中:

conda create -n gdal_test python=3.5
activate gdal_test
conda install gdal

您需要留在此Shell窗口内.即th提示符应该喜欢这个(gdal_test).启动Python:

python
>>> import gdal

注意:在Linux和Mac OS X上,使用source activate gdal_test.

要找出可用的gdal版本,请输入:

conda search gdal

类似这样的输出:

gdal

      ....

               2.0.0               np110py34_0  defaults

意味着gdal 2.0.0可用于Python 3.4,并且需要NumPy 1.10.

Let me start by saying that I have searched for help this problem and gone through the numerous threads that I have found, and none of them have worked, or I wasn't able to understand what they are saying to do.

Once such thread is here: Python GDAL package missing header file when installing via pip

I was able to run

pip install --no-install GDAL

But then I was instructed to "cd into ENV/build/GDAL". I know what cd means but I have no idea where this /ENV/build/GDAL diretory would be located and there is no more information about it in the post, or in the post that it references.

The core problem is just that I want to install GDAL for use in Python. I tried

pip install GDAL, and it failed with this output:

    Collecting GDAL
  Using cached GDAL-2.0.1.tar.gz
Installing collected packages: GDAL
  Running setup.py install for GDAL
    Complete output from command c:\users\isaac\appdata\local\programs\python\python35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Isaac\\AppData\\Local\\Temp\\pip-build-4kmkv1_4\\GDAL\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Isaac\AppData\Local\Temp\pip-fxko2gfx-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.5
    copying gdal.py -> build\lib.win32-3.5
    copying ogr.py -> build\lib.win32-3.5
    copying osr.py -> build\lib.win32-3.5
    copying gdalconst.py -> build\lib.win32-3.5
    creating build\lib.win32-3.5\osgeo
    copying osgeo\gdal.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdalconst.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdalnumeric.py -> build\lib.win32-3.5\osgeo
    copying osgeo\gdal_array.py -> build\lib.win32-3.5\osgeo
    copying osgeo\ogr.py -> build\lib.win32-3.5\osgeo
    copying osgeo\osr.py -> build\lib.win32-3.5\osgeo
    copying osgeo\__init__.py -> build\lib.win32-3.5\osgeo
    Fixing build\lib.win32-3.5\gdal.py build\lib.win32-3.5\ogr.py build\lib.win32-3.5\osr.py build\lib.win32-3.5\gdalconst.py build\lib.win32-3.5\osgeo\gdal.py build\lib.win32-3.5\osgeo\gdalconst.py build\lib.win32-3.5\osgeo\gdalnumeric.py build\lib.win32-3.5\osgeo\gdal_array.py build\lib.win32-3.5\osgeo\ogr.py build\lib.win32-3.5\osgeo\osr.py build\lib.win32-3.5\osgeo\__init__.py
    Skipping optional fixer: ws_comma
    Fixing build\lib.win32-3.5\gdal.py build\lib.win32-3.5\ogr.py build\lib.win32-3.5\osr.py build\lib.win32-3.5\gdalconst.py build\lib.win32-3.5\osgeo\gdal.py build\lib.win32-3.5\osgeo\gdalconst.py build\lib.win32-3.5\osgeo\gdalnumeric.py build\lib.win32-3.5\osgeo\gdal_array.py build\lib.win32-3.5\osgeo\ogr.py build\lib.win32-3.5\osgeo\osr.py build\lib.win32-3.5\osgeo\__init__.py
    Skipping optional fixer: ws_comma
    running build_ext
    building 'osgeo._gdal' extension
    error: [WinError 2] The system cannot find the file specified

Command "c:\users\isaac\appdata\local\programs\python\python35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Isaac\\AppData\\Local\\Temp\\pip-build-07o7k41s\\gdal\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Isaac\AppData\Local\Temp\pip-640gw1ah-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Isaac\AppData\Local\Temp\pip-build-07o7k41s\gdal

Can someone please help me with this? I'm completely lost and have no idea what to do about this.

I'm wondering if maybe it's because my python installation is in a funny place? It's installed at C:\Users\Isaac\AppData\Local\Programs\Python\Python35-32\, which is where it was placed when I installed PyCharm, but that folder and the /Scripts/ folder inside are in my PATH.

Edit: After a bit more research I'm wondering if it's because I'm using Python 3.5? I'll try rolling back to Python 3.4 and see if it changes anything

Edit 2: Nope, no luck, it still fails and tells me

error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat)

I tried to install Microsoft Visual C++ 10.0 and it just told me that there was already a newer version on my computer.

解决方案

Probably the easiest way to install such kind of libraries is conda. Get and install Miniconda as user, not root. Now, create a new environment and install gdal into it:

conda create -n gdal_test python=3.5
activate gdal_test
conda install gdal

You need to stay inside this shell window. i.e. th prompt should like this (gdal_test). Start Python:

python
>>> import gdal

Note: On Linux and Mac OS X use source activate gdal_test.

To find out what versions of gdal are available, type:

conda search gdal

An output like this:

gdal

      ....

               2.0.0               np110py34_0  defaults

means gdal 2.0.0 is available for Python 3.4 and needs NumPy 1.10.

这篇关于在为Python安装GDAL时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆