为 python 安装 GDAL 时遇到问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34408699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Having trouble installing GDAL for python
提问by wfgeo
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
一旦这样的线程在这里:Python GDAL package missing header file when installation 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.
但后来我被指示“进入 ENV/build/GDAL”。我知道 cd 是什么意思,但我不知道这个 /ENV/build/GDAL 目录的位置,并且在帖子或它引用的帖子中没有关于它的更多信息。
The core problem is just that I want to install GDAL for use in Python. I tried
核心问题只是我想安装 GDAL 以在 Python 中使用。我试过
pip install GDAL, and it failed with this output:
pip install 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
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.
我想知道是否可能是因为我的 python 安装在一个有趣的地方?它安装在 C:\Users\Isaac\AppData\Local\Programs\Python\Python35-32\,这是我安装 PyCharm 时放置它的位置,但该文件夹和里面的 /Scripts/ 文件夹在我的 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
编辑:经过更多研究,我想知道是不是因为我使用的是 Python 3.5?我会尝试回滚到 Python 3.4,看看它是否有任何改变
Edit 2: Nope, no luck, it still fails and tells me
编辑 2:不,不走运,它仍然失败并告诉我
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.
我尝试安装 Microsoft Visual C++ 10.0,它只是告诉我我的计算机上已经有更新的版本。
采纳答案by Mike Müller
Probably the easiest way to install such kind of libraries is conda
. Get and install Minicondaas user, not root. Now, create a new environment and install gdal
into it:
安装此类库的最简单方法可能是conda
. 以用户而非 root 身份获取并安装Miniconda。现在,创建一个新环境并安装gdal
到其中:
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:
您需要留在此外壳窗口内。即提示应该是这样的(gdal_test)
。启动 Python:
python
>>> import gdal
Note: On Linux and Mac OS X use source activate gdal_test
.
注意:在 Linux 和 Mac OS X 上使用source activate gdal_test
.
To find out what versions of gdal
are available, type:
要了解gdal
可用的版本,请键入:
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.
意味着gdal 2.0.0
可用于 Python 3.4 并且需要 NumPy 1.10。
回答by Kersten
On Windows the easiest way to install GDAL is to use pre-built binaries unless you have special needs that require building GDAL from source. Apart from conda
, as mentioned by @Mike Müller, there are three common sources for GDAL Windows binaries (with Python bindings):
在 Windows 上,安装 GDAL 的最简单方法是使用预构建的二进制文件,除非您有需要从源代码构建 GDAL 的特殊需求。除了conda
@Mike Müller 提到的之外,GDAL Windows 二进制文件(带有 Python 绑定)有三个常见来源:
回答by PIYUSH AGGARWAL
To install GDAL on windows, you need to follow the below-mentioned step: -
要在 Windows 上安装 GDAL,您需要按照以下步骤操作:-
- You need to install GDAL wheel file using the link https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal. After visiting this link, download this file named "GDAL?3.0.4?cp37?cp37m?win32.whl" since it worked for me and then use the command "pip install c:\Users........\GDAL?3.0.4?cp37?cp37m?win32.whl" to successfully install GDAL which is the requirement of Geopandas.
- 您需要使用链接https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal安装 GDAL 轮文件。访问此链接后,下载名为“GDAL?3.0.4?cp37?cp37m?win32.whl”的文件,因为它对我有用,然后使用命令“pip install c:\Users........\ GDAL?3.0.4?cp37?cp37m?win32.whl”以成功安装Geopandas要求的GDAL。
NOTE: If the above-mentioned wheel file doesn't work for you, then try using alternate wheel files.
注意:如果上述车轮文件对您不起作用,请尝试使用备用车轮文件。