Ubuntu 20.04 s2geometry setup

Ubuntu 20.04 Build S2

Build s2geometry C++ and python3

Environment

OS: Ubuntu 20.04
Python: /usr/bin/python3
Date: 2020-10-08
Now s2geometry supports Python3 officially.

Preparations

sudo apt-get install cmake libgflags-dev libgoogle-glog-dev libgtest-dev libssl-dev
sudo apt-get install python3-dev
sudo apt-get install g++
sudo apt-get install swig # to compile python3 binding
git clone https://github.com/google/s2geometry
cd s2geometry
mkdir build
cd build
cmake -DGTEST_ROOT=/usr/src/gtest ..
make # make -j4 (to speed up)
sudo make install

cmake will generate CMakeCache.txt in build dir, and CMAKE_INSTALL_PREFIX:PATH
defaults to /usr/local. So the target files like libs2.so will be installed to /usr/local/bin where is not in PATH by default.

In StackOverflow, an answer in importerror-libs2-so-cannot-open-shared-object-file-no-such-file-or-directory tells us to modify CMakeCache.txt the value of CMAKE_INSTALL_PREFIX:PATH from /usr/local to /usr . Then do the installation step again. This works.

$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywraps2 as s2 # works here
>>> quit()

Setup a pure virtualenv for s2

Reference blog

install pip3 virtualenv virtualenvwrapper

sudo apt install python3-pip
pip3 install virtualenv
pip3 install virtualenvwrapper

# install path: ~/.local/bin
# warning: install path ~/.local/bin is not in PATH

Then we need modify ~/.bashrc, add following lines.

export PATH="$PATH:~/.local/bin"
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh

Then source ~/.bashrc we can see virtualenvwrapper prepare functions for us.

user@hostname:~$ source ~/.bashrc 
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/yazheng/.virtualenvs/get_env_details

Mkvirtualenv and Install packages

mkvirtualenv s2
python -v # Python 3.8.5
pip -V # pip        20.2.3
pip install jupyter
pip install cython
pip install numpy
pip install matplotlib scikit-learn scipy Shapely folium geojson

# Preparation
sudo apt-get install libgeos-dev
sudo apt-get install libgeos++-dev
sudo apt-get install proj-bin
sudo apt-get install libproj-dev
pip install Cartopy # this requires Proj 4.9.0

[1]: pip install virtualenv
[2]: pip install virtualenvwrapper
[3]: pip install Cartopy
[4]: google-s2-python-jupyter

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值