如何在Ubuntu中安装GDAL?

wwtsj6pe  于 2022-11-02  发布在  其他
关注(0)|答案(3)|浏览(398)

我已经安装了Ubuntu 17.04版本,我想安装GDAL。我尝试了几种方法来安装它,但总是出现错误。我已经安装了Python 2.7和Python 3.6,但我想安装Python 2.7
我已经尝试按照以下步骤进行安装:

  1. sudo apt-get install libgdal-dev export
  2. CPLUS_INCLUDE_PATH=/usr/include/gdal export
  3. C_INCLUDE_PATH=/usr/include/gdal pip install GDAL

我得到了这个错误:

  1. Collecting GDAL
  2. Using cached GDAL-2.2.3.tar.gz
  3. Installing collected packages: GDAL
  4. Running setup.py install for GDAL ... error
  5. Complete output from command /usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-iebgcn_u/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-x3vhb2t4-record/install-record.txt --single-version-externally-managed --compile:
  6. running install
  7. running build
  8. running build_py
  9. creating build
  10. creating build/lib.linux-x86_64-3.6
  11. copying gdal.py -> build/lib.linux-x86_64-3.6
  12. copying ogr.py -> build/lib.linux-x86_64-3.6
  13. copying osr.py -> build/lib.linux-x86_64-3.6
  14. copying gdalconst.py -> build/lib.linux-x86_64-3.6
  15. copying gnm.py -> build/lib.linux-x86_64-3.6
  16. creating build/lib.linux-x86_64-3.6/osgeo
  17. copying osgeo/gdal.py -> build/lib.linux-x86_64-3.6/osgeo
  18. copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.6/osgeo
  19. copying osgeo/osr.py -> build/lib.linux-x86_64-3.6/osgeo
  20. copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.6/osgeo
  21. copying osgeo/ogr.py -> build/lib.linux-x86_64-3.6/osgeo
  22. copying osgeo/gnm.py -> build/lib.linux-x86_64-3.6/osgeo
  23. copying osgeo/__init__.py -> build/lib.linux-x86_64-3.6/osgeo
  24. copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.6/osgeo
  25. Fixing build/lib.linux-x86_64-3.6/gdal.py build/lib.linux-x86_64-3.6/ogr.py build/lib.linux-x86_64-3.6/osr.py build/lib.linux-x86_64-3.6/gdalconst.py build/lib.linux-x86_64-3.6/gnm.py build/lib.linux-x86_64-3.6/osgeo/gdal.py build/lib.linux-x86_64-3.6/osgeo/gdal_array.py build/lib.linux-x86_64-3.6/osgeo/osr.py build/lib.linux-x86_64-3.6/osgeo/gdalconst.py build/lib.linux-x86_64-3.6/osgeo/ogr.py build/lib.linux-x86_64-3.6/osgeo/gnm.py build/lib.linux-x86_64-3.6/osgeo/__init__.py build/lib.linux-x86_64-3.6/osgeo/gdalnumeric.py
  26. Skipping optional fixer: ws_comma
  27. Fixing build/lib.linux-x86_64-3.6/gdal.py build/lib.linux-x86_64-3.6/ogr.py build/lib.linux-x86_64-3.6/osr.py build/lib.linux-x86_64-3.6/gdalconst.py build/lib.linux-x86_64-3.6/gnm.py build/lib.linux-x86_64-3.6/osgeo/gdal.py build/lib.linux-x86_64-3.6/osgeo/gdal_array.py build/lib.linux-x86_64-3.6/osgeo/osr.py build/lib.linux-x86_64-3.6/osgeo/gdalconst.py build/lib.linux-x86_64-3.6/osgeo/ogr.py build/lib.linux-x86_64-3.6/osgeo/gnm.py build/lib.linux-x86_64-3.6/osgeo/__init__.py build/lib.linux-x86_64-3.6/osgeo/gdalnumeric.py
  28. Skipping optional fixer: ws_comma
  29. running build_ext
  30. building 'osgeo._gdal' extension
  31. creating build/temp.linux-x86_64-3.6
  32. creating build/temp.linux-x86_64-3.6/extensions
  33. x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python3.6m -I. -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.6/extensions/gdal_wrap.o
  34. cc1plus: warning: command line option ‘-Wstrict-prototypes is valid for C/ObjC but not for C++
  35. x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/extensions/gdal_wrap.o -L../../.libs -L../../ -lgdal -o build/lib.linux-x86_64-3.6/osgeo/_gdal.cpython-36m-x86_64-linux-gnu.so
  36. building 'osgeo._gdalconst' extension
  37. x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python3.6m -I. -I/usr/include -c extensions/gdalconst_wrap.c -o build/temp.linux-x86_64-3.6/extensions/gdalconst_wrap.o
  38. x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/extensions/gdalconst_wrap.o -L../../.libs -L../../ -lgdal -o build/lib.linux-x86_64-3.6/osgeo/_gdalconst.cpython-36m-x86_64-linux-gnu.so
  39. building 'osgeo._osr' extension
  40. x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python3.6m -I. -I/usr/include -c extensions/osr_wrap.cpp -o build/temp.linux-x86_64-3.6/extensions/osr_wrap.o
  41. cc1plus: warning: command line option ‘-Wstrict-prototypes is valid for C/ObjC but not for C++
  42. extensions/osr_wrap.cpp:3339:13: warning: void GDALPythonFreeCStr(void*, int)’ defined but not used [-Wunused-function]
  43. static void GDALPythonFreeCStr(void* ptr, int bToFree)
  44. ^~~~~~~~~~~~~~~~~~
  45. extensions/osr_wrap.cpp:3309:14: warning: char* GDALPythonObjectToCStr(PyObject*, int*)’ defined but not used [-Wunused-function]
  46. static char* GDALPythonObjectToCStr(PyObject* pyObject, int* pbToFree)
  47. ^~~~~~~~~~~~~~~~~~~~~~
  48. x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/extensions/osr_wrap.o -L../../.libs -L../../ -lgdal -o build/lib.linux-x86_64-3.6/osgeo/_osr.cpython-36m-x86_64-linux-gnu.so
  49. building 'osgeo._ogr' extension
  50. x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python3.6m -I. -I/usr/include -c extensions/ogr_wrap.cpp -o build/temp.linux-x86_64-3.6/extensions/ogr_wrap.o
  51. cc1plus: warning: command line option ‘-Wstrict-prototypes is valid for C/ObjC but not for C++
  52. x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/extensions/ogr_wrap.o -L../../.libs -L../../ -lgdal -o build/lib.linux-x86_64-3.6/osgeo/_ogr.cpython-36m-x86_64-linux-gnu.so
  53. building 'osgeo._gnm' extension
  54. x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python3.6m -I. -I/usr/include -c extensions/gnm_wrap.cpp -o build/temp.linux-x86_64-3.6/extensions/gnm_wrap.o
  55. cc1plus: warning: command line option ‘-Wstrict-prototypes is valid for C/ObjC but not for C++
  56. extensions/gnm_wrap.cpp:3321:13: warning: void GDALPythonFreeCStr(void*, int)’ defined but not used [-Wunused-function]
  57. static void GDALPythonFreeCStr(void* ptr, int bToFree)
  58. ^~~~~~~~~~~~~~~~~~
  59. extensions/gnm_wrap.cpp:3291:14: warning: char* GDALPythonObjectToCStr(PyObject*, int*)’ defined but not used [-Wunused-function]
  60. static char* GDALPythonObjectToCStr(PyObject* pyObject, int* pbToFree)
  61. ^~~~~~~~~~~~~~~~~~~~~~
  62. x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-Bsymbolic-functions -specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/extensions/gnm_wrap.o -L../../.libs -L../../ -lgdal -o build/lib.linux-x86_64-3.6/osgeo/_gnm.cpython-36m-x86_64-linux-gnu.so
  63. running install_lib
  64. copying build/lib.linux-x86_64-3.6/gdal.py -> /usr/local/lib/python3.6/dist-packages
  65. error: could not create '/usr/local/lib/python3.6/dist-packages/gdal.py': Permission denied
  66. ----------------------------------------
  67. Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-iebgcn_u/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-x3vhb2t4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-iebgcn_u/GDAL/

如果我使用sudo执行最后一个命令:sudo pip安装GDAL。我得到了这个另一个错误...

  1. The directory '/home/josecarlos/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/home/josecarlos/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting GDAL Downloading GDAL-2.2.3.tar.gz (475kB)
  2. 100% |████████████████████████████████| 481kB 1.3MB/s Installing collected packages: GDAL Running setup.py install for GDAL ... error
  3. Complete output from command /usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-0rp6w4f8/GDAL/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install
  4. --record /tmp/pip-w7crvfsd-record/install-record.txt --single-version-externally-managed --compile:
  5. running install
  6. running build
  7. running build_py
  8. creating build
  9. creating build/lib.linux-x86_64-3.6
  10. copying gdal.py -> build/lib.linux-x86_64-3.6
  11. copying ogr.py -> build/lib.linux-x86_64-3.6
  12. copying osr.py -> build/lib.linux-x86_64-3.6
  13. copying gdalconst.py -> build/lib.linux-x86_64-3.6
  14. copying gnm.py -> build/lib.linux-x86_64-3.6
  15. creating build/lib.linux-x86_64-3.6/osgeo
  16. copying osgeo/gdal.py -> build/lib.linux-x86_64-3.6/osgeo
  17. copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.6/osgeo
  18. copying osgeo/osr.py -> build/lib.linux-x86_64-3.6/osgeo
  19. copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.6/osgeo
  20. copying osgeo/ogr.py -> build/lib.linux-x86_64-3.6/osgeo
  21. copying osgeo/gnm.py -> build/lib.linux-x86_64-3.6/osgeo
  22. copying osgeo/__init__.py -> build/lib.linux-x86_64-3.6/osgeo
  23. copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.6/osgeo
  24. Fixing build/lib.linux-x86_64-3.6/gdal.py build/lib.linux-x86_64-3.6/ogr.py build/lib.linux-x86_64-3.6/osr.py build/lib.linux-x86_64-3.6/gdalconst.py build/lib.linux-x86_64-3.6/gnm.py build/lib.linux-x86_64-3.6/osgeo/gdal.py build/lib.linux-x86_64-3.6/osgeo/gdal_array.py build/lib.linux-x86_64-3.6/osgeo/osr.py build/lib.linux-x86_64-3.6/osgeo/gdalconst.py build/lib.linux-x86_64-3.6/osgeo/ogr.py build/lib.linux-x86_64-3.6/osgeo/gnm.py build/lib.linux-x86_64-3.6/osgeo/__init__.py build/lib.linux-x86_64-3.6/osgeo/gdalnumeric.py
  25. Skipping optional fixer: ws_comma
  26. Fixing build/lib.linux-x86_64-3.6/gdal.py build/lib.linux-x86_64-3.6/ogr.py build/lib.linux-x86_64-3.6/osr.py build/lib.linux-x86_64-3.6/gdalconst.py build/lib.linux-x86_64-3.6/gnm.py build/lib.linux-x86_64-3.6/osgeo/gdal.py build/lib.linux-x86_64-3.6/osgeo/gdal_array.py build/lib.linux-x86_64-3.6/osgeo/osr.py build/lib.linux-x86_64-3.6/osgeo/gdalconst.py build/lib.linux-x86_64-3.6/osgeo/ogr.py build/lib.linux-x86_64-3.6/osgeo/gnm.py build/lib.linux-x86_64-3.6/osgeo/__init__.py build/lib.linux-x86_64-3.6/osgeo/gdalnumeric.py
  27. Skipping optional fixer: ws_comma
  28. running build_ext
  29. building 'osgeo._gdal' extension
  30. creating build/temp.linux-x86_64-3.6
  31. creating build/temp.linux-x86_64-3.6/extensions
  32. x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/usr/include/python3.6m -I. -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.6/extensions/gdal_wrap.o
  33. cc1plus: warning: command line option ‘-Wstrict-prototypes is valid for C/ObjC but not for C++
  34. extensions/gdal_wrap.cpp:3168:10: fatal error: cpl_port.h: No existe el archivo o el directorio
  35. #include "cpl_port.h"
  36. ^~~~~~~~~~~~
  37. compilation terminated.
  38. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  39. ---------------------------------------- Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-0rp6w4f8/GDAL/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install
  40. --record /tmp/pip-w7crvfsd-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-0rp6w4f8/GDAL/

如何在Ubuntu中安装GDAL?

nle07wnf

nle07wnf1#

如果您下载该软件包并阅读readme.txt.downloadpage,可能会有更多的选择
我自己对所有这些命令参数都不那么有信心。
希望能有所帮助

oprakyz7

oprakyz72#

也许问题是Ubuntu版本比Python版本多,我没有找到很多关于ubuntu17的信息,所以你应该试试更老更稳定的版本。

ryevplcw

ryevplcw3#

我有Ubuntu 18.04和this answer似乎也帮助了她。根据评论,它也在Ubuntu 16.04和14.04上工作:

如果您没有安装任何gdal先前版本

打开终端并键入

  1. sudo add-apt-repository -y ppa:ubuntugis/ppa
  2. sudo apt update
  3. sudo apt install gdal-bin python-gdal python3-gdal

如果您安装了以前的版本

打开终端并键入

  1. sudo add-apt-repository -y ppa:ubuntugis/ppa
  2. sudo apt update
  3. sudo apt upgrade
展开查看全部

相关问题