您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何在python中安裝gdal,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
1.不用手動下載文件,直接執行以下命令即可
conda install gdal
2.首先,下載gdal的whl文件 鏈接, 官網下載比較慢,GDAL-2.2.4-cp27-cp27m-win_amd64.whl
鏈接: https://pan.baidu.com/s/1prPHLJKwoKK505i5qTVZ7g
提取碼: egj6
有百度云可以下載,然后放入本機目錄。
這里目錄有兩種,一是放入anaconda安裝目錄的Scripts目錄,我的是D:\anaconda\Scripts目錄;二是放入Anaconda環境的Scripts目錄,我的是D:\anaconda\envs\uav\Scripts(uav是我自己的環境,可通過命令conda create -n name python=3.6創建環境)。
最后,在D:\Anaconda3\Scripts目錄下在空白處按住shift加右鍵打開cmd,輸入以下命令即可。
pip install GDAL?3.0.1?cp38?cp38?win_amd64.whl
注:若用pip安裝gdal會報錯:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gdal
報錯信息如下:
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting gdal Downloading https://pypi.tuna.tsinghua.edu.cn/packages/26/c6/f8846ba726b37f9a1099acb5bff43c309fb913577674c1ba491f6fc60598/GDAL-3.0.1.tar.gz (576kB) |████████████████████████████████| 583kB 810kB/s Building wheels for collected packages: gdal Building wheel for gdal (setup.py) ... error ERROR: Complete output from command /home/dennis/miniconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-i321u6em/gdal/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-aaneihet --python-tag cp37: ERROR: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.7 copying gdal.py -> build/lib.linux-x86_64-3.7 copying ogr.py -> build/lib.linux-x86_64-3.7 copying osr.py -> build/lib.linux-x86_64-3.7 copying gdalconst.py -> build/lib.linux-x86_64-3.7 copying gdalnumeric.py -> build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/osr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gnm.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/__init__.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/ogr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.7/osgeo Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma running build_ext gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o -std=c++11 building 'osgeo._gdal' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/extensions gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.7/extensions/gdal_wrap.o -std=c++11 -I/home/dennis/miniconda3/include cc1plus: warning: command line option ‘-Wstrict-prototypes' is valid for C/ObjC but not for C++ extensions/gdal_wrap.cpp:4075:1: error: ‘VSIDIR' does not name a type VSIDIR* wrapper_VSIOpenDir( const char * utf8_path, ^ extensions/gdal_wrap.cpp:4123:38: error: ‘VSIDIR' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4123:46: error: ‘dir' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4124:1: error: expected ‘,' or ‘;' before ‘{' token { ^ extensions/gdal_wrap.cpp:3225:7: warning: ‘char* get_aligned_buffer(char*, GDALDataType)' defined but not used [-Wunused-function] char* get_aligned_buffer(char* data, GDALDataType ntype) ^ extensions/gdal_wrap.cpp:3244:13: warning: ‘void update_buffer_size(void*, char*, char*, size_t)' defined but not used [-Wunused-function] static void update_buffer_size(void* obj, char* data, char* data_aligned, size_t buf_size) ^ extensions/gdal_wrap.cpp:3299:5: warning: ‘int GetUseExceptions()' defined but not used [-Wunused-function] int GetUseExceptions() { ^ extensions/gdal_wrap.cpp:3305:6: warning: ‘void UseExceptions()' defined but not used [-Wunused-function] void UseExceptions() { ^ extensions/gdal_wrap.cpp:3322:6: warning: ‘void DontUseExceptions()' defined but not used [-Wunused-function] void DontUseExceptions() { ^ extensions/gdal_wrap.cpp:3370:13: warning: ‘void ClearErrorState()' defined but not used [-Wunused-function] static void ClearErrorState() ^ error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for gdal Running setup.py clean for gdal Failed to build gdal Installing collected packages: gdal Running setup.py install for gdal ... error ERROR: Complete output from command /home/dennis/miniconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-i321u6em/gdal/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-axykekqk/install-record.txt --single-version-externally-managed --compile: ERROR: running install running build running build_py creating build creating build/lib.linux-x86_64-3.7 copying gdal.py -> build/lib.linux-x86_64-3.7 copying ogr.py -> build/lib.linux-x86_64-3.7 copying osr.py -> build/lib.linux-x86_64-3.7 copying gdalconst.py -> build/lib.linux-x86_64-3.7 copying gdalnumeric.py -> build/lib.linux-x86_64-3.7 creating build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/osr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gnm.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/__init__.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/ogr.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal.py -> build/lib.linux-x86_64-3.7/osgeo copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.7/osgeo Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma Fixing build/lib.linux-x86_64-3.7/gdal.py build/lib.linux-x86_64-3.7/ogr.py build/lib.linux-x86_64-3.7/osr.py build/lib.linux-x86_64-3.7/gdalconst.py build/lib.linux-x86_64-3.7/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/gdalconst.py build/lib.linux-x86_64-3.7/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.7/osgeo/osr.py build/lib.linux-x86_64-3.7/osgeo/gnm.py build/lib.linux-x86_64-3.7/osgeo/__init__.py build/lib.linux-x86_64-3.7/osgeo/ogr.py build/lib.linux-x86_64-3.7/osgeo/gdal.py build/lib.linux-x86_64-3.7/osgeo/gdal_array.py Skipping optional fixer: ws_comma running build_ext gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o -std=c++11 building 'osgeo._gdal' extension creating build/temp.linux-x86_64-3.7 creating build/temp.linux-x86_64-3.7/extensions gcc -pthread -B /home/dennis/miniconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/dennis/miniconda3/include/python3.7m -I/home/dennis/miniconda3/lib/python3.7/site-packages/numpy/core/include -I/home/dennis/miniconda3/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.7/extensions/gdal_wrap.o -std=c++11 -I/home/dennis/miniconda3/include cc1plus: warning: command line option ‘-Wstrict-prototypes' is valid for C/ObjC but not for C++ extensions/gdal_wrap.cpp:4075:1: error: ‘VSIDIR' does not name a type VSIDIR* wrapper_VSIOpenDir( const char * utf8_path, ^ extensions/gdal_wrap.cpp:4123:38: error: ‘VSIDIR' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4123:46: error: ‘dir' was not declared in this scope DirEntry* wrapper_VSIGetNextDirEntry(VSIDIR* dir) ^ extensions/gdal_wrap.cpp:4124:1: error: expected ‘,' or ‘;' before ‘{' token { ^ extensions/gdal_wrap.cpp:3225:7: warning: ‘char* get_aligned_buffer(char*, GDALDataType)' defined but not used [-Wunused-function] char* get_aligned_buffer(char* data, GDALDataType ntype) ^ extensions/gdal_wrap.cpp:3244:13: warning: ‘void update_buffer_size(void*, char*, char*, size_t)' defined but not used [-Wunused-function] static void update_buffer_size(void* obj, char* data, char* data_aligned, size_t buf_size) ^ extensions/gdal_wrap.cpp:3299:5: warning: ‘int GetUseExceptions()' defined but not used [-Wunused-function] int GetUseExceptions() { ^ extensions/gdal_wrap.cpp:3305:6: warning: ‘void UseExceptions()' defined but not used [-Wunused-function] void UseExceptions() { ^ extensions/gdal_wrap.cpp:3322:6: warning: ‘void DontUseExceptions()' defined but not used [-Wunused-function] void DontUseExceptions() { ^ extensions/gdal_wrap.cpp:3370:13: warning: ‘void ClearErrorState()' defined but not used [-Wunused-function] static void ClearErrorState() ^ error: command 'gcc' failed with exit status 1 ---------------------------------------- ERROR: Command "/home/dennis/miniconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-i321
Python是一種跨平臺的、具有解釋性、編譯性、互動性和面向對象的腳本語言,其最初的設計是用于編寫自動化腳本,隨著版本的不斷更新和新功能的添加,常用于用于開發獨立的項目和大型項目。
關于如何在python中安裝gdal就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。