由于有不少python
包是用c
编写的,这样一来在不同的CPU
架构(x86,MIPS64等,python 默认提供的是x86架构的包)上使用时需要重新编译。目前有两种方法来处理这个问题。
pip
在线安装,利用pip
在线安装时会自动下载相应的源码包并编译的功能使用这两种方法时都得安装编译环境及编译此包所需的依赖,不然就会出现编译失败或安装失败的提示。
用 pip install
安装时,如果找不到相应的.whl
包,则自动下载源码之后进行编译。编译后的包在~/.cache/pip/wheels
目录下。可以把这些编译好的.whl
文件复制出来。
pip
安装时的cahce
目录可以通过命令来查看。相关参考:https://pip.pypa.io/en/stable/reference/pip_cache/
# pip cache dir
/root/.cache/pip
$ pip install pyarrow
Collecting pyarrow
Downloading https://files.pythonhosted.org/packages/ed/c9/85d179d5a0575e1b066fb94bfe1e37b6d3ca546b58e75b9d1ca4952320de/pyarrow-0.17.1.tar.gz (2.6MB)
100% |████████████████████████████████| 2.6MB 146kB/s
Installing build dependencies ... done
Requirement already satisfied: numpy>=1.14 in /home/loongson-gd/.local/lib/python3.7/site-packages (from pyarrow) (1.18.5)
Building wheels for collected packages: pyarrow
Running setup.py bdist_wheel for pyarrow ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-ekyp7jb9/pyarrow/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-ca7vzlm6 --python-tag cp37:
running bdist_wheel
$ cd opencv-python-34
$ python3 setup.py bdist_wheel
Collecting numpy==1.14.5
Using cached https://files.pythonhosted.org/packages/d5/6e/f00492653d0fdf6497a181a1c1d46bbea5a2383e7faf4c8ca6d6f3d2581d/numpy-1.14.5.zip
Building wheels for collected packages: numpy
~/wheel
目录脚本如下:#!/bin/bash
##此目录用来存放待提取的whl包
mkdir -p ~/wheel
cd ~/.cache/pip/wheels
for f in `find . -name "*.whl"`
do
echo $f
cp $f ~/wheel -rvf
done