有时候装一个第三方库时,看到除了安装还有build,比如这下面这个:
Get segyio
A copy of segyio is available both as pre-built binaries and source code:
In Debian unstable
apt install python3-segyio
Wheels for Python from PyPI
pip install segyio
Source code from github
git clone https://github.com/statoil/segyio
Source code in tarballs
Build segyio
To build segyio you need:
A C99 compatible C compiler (tested mostly on gcc and clang)
A C++ compiler for the Python extension, and C++11 for the tests
CMake version 2.8.12 or greater
Python 2.7 or 3.x.
numpy version 1.10 or greater
setuptools version 28 or greater
setuptools-scm
pytest
To build the documentation, you also need sphinx
To build and install segyio, perform the following actions in your console:
git clone https://github.com/Statoil/segyio
mkdir segyio/build
cd segyio/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local
make
make install
我pip install 这个segyio包不是就可以用了吗?还需要build吗?这个build是什么意思呢?
因为python的运行速度慢,所以很多python库采用C语言实现,那么C语言要经过编译才能执行。
那么有两个情况,第一个是作者编译好了,打包好,那么就是pip install那种。
还有一个是作者提供源代码,你自己编译、安装。
通常前者就可以了,除非:
(1)你需要修改源代码,修正某个bug,或者添加/修改功能
(2)你的硬件是预编译的包不支持的,假设作者的预编译包只支持x86,而你希望在一个树莓派(ARM cpu)上运行,就要自己编译。
或者说作者按照x86编译,但是你的cpu是新的,支持一种新的指令,可以加速运算,那么重新编译可以提高速度。
但是以上两者基本上很难遇见,因为基本常见的包都已经预编译好了。