CentOS,anaconda,python,tensorflow環境下gdal的編譯和問題解決

CentOS7.4,anaconda3,python3.6,tensorflow環境下gdal的編譯和問題解決

這是gdal可能會用到的額外的包,按本身須要先提早編譯。 這裏的話我主要用了proj,Libtiff,Geotiff,Geos,Hdf5這5個包,基本能知足須要python

安裝步驟

新建一個安裝目錄:c++

cd /home/Elam
mkdir gdalsrc
cd gdalsrc

編譯額外包:

1.proj

yum install gcc-c++
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar -zxvf proj-4.8.0.tar.gz 
cd proj-4.8.0
mkdir build
./configure --prefix=/home/Elam/gdalsrc/proj-4.8.0/build
# compile
make -j
# install into build dir
make install

建立一個統一的添加環境變量的文件夾:sql

cd /home/Elam/gdalsrc
mkdir envsh
cd envsh
vim export_path.sh

添加下面兩行代碼vim

export LD_LIBRARY_PATH="/home/Elam/gdalsrc/proj-4.8.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/hoem/Elam/gdalsrc/proj-4.8.0/build/bin:$PATH"

能夠source export_path.sh 而後鍵入proj看看是否編譯成功curl

2.libtiff

yum install gcc-c++ zlib-devel libjpeg-turbo-devel
cd /home/Elam/gdalsrc
wget http://download.osgeo.org/libtiff/tiff-4.0.9.tar.gz  最新版本是4.0.9
tar -zxvf tiff-4.0.9.tar.gz
cd tiff-4.0.9

ls一下發現build文件夾已經存在,所以不須要從新建立直接configurepost

./configure --prefix=/home/Elam/gdalsrc/tiff-4.0.9/build/ \
            --exec-prefix=/home/Elam/gdalsrc/tiff-4.0.9/build
make -j
make check
# install to build dir
make install
# confirm install
./build/bin/tiffinfo

進入剛纔建立的export_path添加新的環境變量,以下圖:ui

source一下url

3.Geotiff

在gdalsrc目錄下3d

wget http://download.osgeo.org/geotiff/libgeotiff/libgeotiff-1.4.2.tar.gz
tar -xvfz libgeotiff-1.4.2.tar.gz 
cd libgeotiff-1.4.2/
mkdir build
./configure --prefix=/home/Elam/gdalsrc/libgeotiff-1.4.2/build \
            --with-proj=/home/Elam/gdalsrc/proj-4.8.0/build \
            --with-libtiff=/home/Elam/gdalsrc/tiff-4.0.9/build \
            --with-zlib --with-jpeg
# compile
make -j
# install into build dir
make install

進入export_path添加新的環境變量,以下圖:unix

source一下

4.Geos

yum install gcc-c++ swig python-devel
cd /home/Elam/gdalsrc
wget http://download.osgeo.org/geos/geos-3.6.2.tar.bz2
tar -xvjf geos-3.6.2.tar.bz2 
cd geos-3.6.2
mkdir build
./configure --prefix=/home/Elam/gdalsrc/geos-3.6.2/build --enable-python
# compile    
make -j$threads
make check
# install into build dir
make install
# check install
./build/bin/geos-config --version

gdal編譯過程當中碰到的問題主要出如今編譯這個庫中

錯誤:

./configure --prefix=/home/Elam/gdalsrc/geos-3.6.2/build --enable-python

configure出現cannot find Python library path錯誤:

解決方法: vim configure 在左下角輸入/cannot find Python library path 回車 找到對應行附近 [圖片上傳失敗...(image-5ecfa3-1528652621967)] 將libpython$PYTHOH_VERSION改爲你本身對應的.so和.a版本(具體版本能夠到上面include路徑同一路徑下lib文件夾中查看) 如上 我改爲了libpython3.6m 修改後:wq 從新configure

繼續修改configure文件

[圖片上傳失敗...(image-a183a3-1528652621967)]

從新configure 若是後續還報/usr/bin/ld: cannot find -lpython3.6錯誤 繼續修改

從新configure 而後繼續

make –j  
make check
make install

添加新的環境變量

source

5.hdf5

yum install gcc-c++ zlib-devel
cd /home/Elam/gdalsrc
wget http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.11.tar.gz
tar xvfz hdf5-1.8.11.tar.gz
cd hdf5-1.8.11
touch release_docs/INSTALL_VMS.txt
mkdir build
CFLAGS=-O0 \
./configure \
  --prefix=/home/Elam/gdalsrc/hdf5-1.10.1/build \
  --enable-shared \
  --enable-build-all \
  --with-zlib \
  --with-pthread \
  --enable-cxx \
# compile
make -j
# test build -- all tests should pass
make -j check
# install into build dir
make install

添加新的環境變量,注意這裏還有include文件夾

gdal編譯

我從網上下了一個2.3.0版本的,網址:http://download.osgeo.org/gdal/

yum install subversion gcc-c++ sqlite-devel libxml2-devel python-devel numpy swig expat-devel libcurl-devel xerces-c-devel unixODBC-devel postgresql postgresql-devel
cd /home/Elam/gdalsrc
tar -zxvf gdal-2.3.0.tar.gz
cd gdal-2.3.0
mkdir build
./configure \
--prefix=/home/Elam/gdalsrc/gdal-2.3.0/build \
--with-jpeg=external \
--without-libtool \
--with-python=/usr/local/anaconda3/bin/python \
--with-static-proj4=/home/Elam/gdalsrc/proj-4.8.0/build \
--with-libtiff=/home/Elam/gdalsrc/tiff-4.0.9/build \
--with-geotiff=/home/Elam/gdalsrc/libgeotiff-1.4.2/build \
--with-geos=/home/Elam/gdalsrc/geos-3.6.2/build/bin/geos-config \
--with-hdf5=/home/Elam/gdalsrc/hdf5-1.10.1/build \

make -j
# install into build dir
make install

添加新的環境變量:

進入build/bin裏面

gdal-config –-version

看看是否編譯成功

cd /home/Elam/gdalsrc/gdal-2.3.0/swig
make -j
cd python
python setup.py install --prefix=/home/Elam/gdalsrc/gdal-2.3.0/build

添加環境變量,或者直接用sys的路子添加路徑

source 從新新建一個終端 先用

echo $PATH
echo $LD_LIBRARY_PATH

查看各個庫的路徑是否都在 若是不在,則從新source一下那個export_path.sh 若是不想每次都從新source,就直接添加到系統的環境變量當中去 進入python終端 看看能不能import

相關文章
相關標籤/搜索