为 python 安装 GDAL 时遇到问题
Having trouble installing GDAL for python
首先我要说的是,我已经搜索过这个问题的帮助,并浏览了我发现的许多线程,其中 none 个有效,或者我无法理解它们的内容说要做。
一旦出现这样的线程:Python GDAL package missing header file when installing via pip
我能够运行
pip install --no-install GDAL
但后来有人指示我 "cd into ENV/build/GDAL"。我知道 cd 是什么意思,但我不知道这个 /ENV/build/GDAL 目录在哪里,在 post 或它引用的 post 中没有关于它的更多信息。
核心问题就是我想安装GDAL在Python中使用。我试过了
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
有人可以帮我解决这个问题吗?我完全迷路了,不知道该怎么办。
我想知道是不是因为我的 python 安装在一个有趣的地方?它安装在C:\Users\Isaac\AppData\Local\Programs\Python\Python35-32\,这是我安装时放置的位置PyCharm,但是那个文件夹和里面的/Scripts/文件夹在我的PATH中。
编辑:经过更多研究后,我想知道是不是因为我使用的是 Python 3.5?我会尝试回滚到 Python 3.4,看看它是否有任何改变
编辑 2:不,运气不好,它仍然失败并告诉我
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 window 里面。即 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。
在 Windows 上,安装 GDAL 的最简单方法是使用预构建的二进制文件,除非您有特殊需要需要从源代码构建 GDAL。除了 conda
,正如@Mike Müller 所提到的,GDAL Windows 二进制文件(具有 Python 绑定)有三个常见来源:
要在 windows 上安装 GDAL,您需要执行以下步骤:-
- 您需要使用 link https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal 安装 GDAL wheel 文件。访问此 link 后,下载名为 "GDAL‑3.0.4‑cp37‑cp37m‑win32.whl" 的文件,因为它对我有用,然后使用命令 "pip install c:\Users........\GDAL‑3.0.4‑cp37‑cp37m‑win32.whl" 成功安装 GDAL,这是 Geopandas 的要求。
注意:如果上述 wheel 文件不适合您,请尝试使用备用 wheel 文件。
首先我要说的是,我已经搜索过这个问题的帮助,并浏览了我发现的许多线程,其中 none 个有效,或者我无法理解它们的内容说要做。
一旦出现这样的线程:Python GDAL package missing header file when installing via pip
我能够运行
pip install --no-install GDAL
但后来有人指示我 "cd into ENV/build/GDAL"。我知道 cd 是什么意思,但我不知道这个 /ENV/build/GDAL 目录在哪里,在 post 或它引用的 post 中没有关于它的更多信息。
核心问题就是我想安装GDAL在Python中使用。我试过了
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
有人可以帮我解决这个问题吗?我完全迷路了,不知道该怎么办。
我想知道是不是因为我的 python 安装在一个有趣的地方?它安装在C:\Users\Isaac\AppData\Local\Programs\Python\Python35-32\,这是我安装时放置的位置PyCharm,但是那个文件夹和里面的/Scripts/文件夹在我的PATH中。
编辑:经过更多研究后,我想知道是不是因为我使用的是 Python 3.5?我会尝试回滚到 Python 3.4,看看它是否有任何改变
编辑 2:不,运气不好,它仍然失败并告诉我
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 window 里面。即 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。
在 Windows 上,安装 GDAL 的最简单方法是使用预构建的二进制文件,除非您有特殊需要需要从源代码构建 GDAL。除了 conda
,正如@Mike Müller 所提到的,GDAL Windows 二进制文件(具有 Python 绑定)有三个常见来源:
要在 windows 上安装 GDAL,您需要执行以下步骤:-
- 您需要使用 link https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal 安装 GDAL wheel 文件。访问此 link 后,下载名为 "GDAL‑3.0.4‑cp37‑cp37m‑win32.whl" 的文件,因为它对我有用,然后使用命令 "pip install c:\Users........\GDAL‑3.0.4‑cp37‑cp37m‑win32.whl" 成功安装 GDAL,这是 Geopandas 的要求。
注意:如果上述 wheel 文件不适合您,请尝试使用备用 wheel 文件。