公司生产环境部署,遇到提供的云服务器是no-avx指令集的,导致之前封装打包的容器镜像不可用,启动报错如下内容:
具体原因需要安装mxnet-noavx版本。查询官网库mxnet-noavx · PyPI,安装mxnet-noavx,还需要两个依赖,libopencv-dev 4.2 和libgfortran5。因此首先需要安装这两个依赖。
这边封装的容器系统是Ubuntu,如果直接使用默认源进行安装,libopencv-dev版本大概率不是4.2,而是3.2之类的。安装之前,可以使用来查看源版本是否匹配
apt-cache madison libopencv-dev
结果包含如下内容即可
如果没有,建议使用Ubuntu20.04的阿里云镜像源,更新源,然后安装,步骤如下:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sh -c 'echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
" > /etc/apt/sources.list'
sudo apt update
完成更新源之后,可以再查询一下版本,大概率是可以的。然后执行安装:
apt-get install libopencv-dev libgfortran5
上述完成安装以后,再卸载现有mxnet(如果已卸载或者未安装,则可跳过):
pip uninstall mxnet
再执行安装mxnet-noavx指令:
pip install mxnet-noavx==2.0.3 -i https://mirror.baidu.com/pypi/simple
如果出现以下错误,说明pip版本过低,需要升级pip再安装:pip install -U pip
安装完成之后,可以进入python,然后import mxnet查看是否能够导入包。
可能会出现python的情况(安装libopencv-dev影响),此时重新配一下软链接。
使用find /usr/bin 'python*'查看自己环境已有python的版本,我的是python3.7,然后使用下面指令新建软链接:
ln -s /usr/bin/python3.7 /usr/bin/python
至此安装mxnet-noavx完成。