背景:由于公司服务器上使用的是REHL6.7,环境离线,且为生产环境,尝试在上面安装infomap这个包时报gcc的版本不对,又不能动生产环境上的gcc版本,只能想着离线拉一个和生产版本一致的系统把环境安装好后再迁移过去
系统环境准备
通过docker search查找REHE找到如下镜像
刚好有个版本一致的6.7的,通过pull命令拉下来后大概600M多。
Python环境准备
里面默认的版本是Python2.6的,我需要的Python版本是3.6.3的,过程中尝试下载了Python3.6的安装包编译安装,各种报错,pip也装不上,后来想到可以直接安装miniconda的,一键搞定
# 下载
wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda-latest-Linux-x86_64.sh
# 安装按步骤安装就行
sh Miniconda-latest-Linux-x86_64.sh
# 切换清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
# 新建一个env_name,用Python3.6并安装numpy pandas等包
conda create -n env_name python=3.6 numpy pandas
# 如果不安装任何包
conda create --no-default-packages -n env_name python
# 环境切换备份
## backup
conda list --explicit > my_env_file.txt
## restore whole environment
conda create --name myenv --file my_env_file.txt
## only install all the listed packages
conda install --name myenv --file my_env_file.txt
这里面使用source activate env_name的时候报错了,应该是路径问题,毕竟是在docker里面,就不去纠结这个了,只用使用绝对路径来使用Python和pip工具
编译工具
infomap需要gcc的版本在4.9以上,但是默认的gcc是4.4.7的,所以需要安装gcc,参考 https://www.cnblogs.com/book-gary/p/5123811.html,其中mpc-0.9.tar.gz这个包下载不了,可以直接搜一下下载地址。
gcc的的包有110M,解压过程需要很久。
需要的5个依赖及其对应的版本,对应的版本可以直接查看gcc目录下的 \gcc-4.9.3/contrib/download_prerequisites
文件
cloog-0.18.1 ftp://gcc.gnu.org/pub/gcc/infrastructure/
gmp-4.3.2 http://ftp.yz.yamagata-u.ac.jp/pub/GNU/gmp/
isl-0.12.2 http://isl.gforge.inria.fr/
mpc-0.8.1 http://ftp.heanet.ie/mirrors/gnu/mpc/
mpfr-2.4.2 http://ftp.gnu.org/gnu/mpfr/
- gmp安装
tar xzf gmp-4.3.2.tar.gz
cd gmp-4.3.2
./configure --prefix=/usr/local/gmp
make && make install
- mpfr 安装
tar xjf mpfr-2.4.2.tar.bz2
cd mpfr-2.4.2
./configure --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --prefix=/usr/local/mpfr
make && make install
- mpc安装
tar xzf mpc-0.8.1.tar.gz
cd mpc-0.8.1
./configure --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --prefix=/usr/local/mpc
make && make install
- isl安装
tar xzf isl-0.12.2.tar.gz
cd isl-0.12.2
./configure --with-gmp-prefix=/usr/local/gmp --prefix=/usr/local/isl
make && make install
- cloog安装
tar xzf cloog-0.18.1.tar.gz
cd cloog-0.18.1
./configure --with-gmp-prefix=/usr/local/gmp -with-isl-prefix=/usr/local/isl --prefix=/usr/local/cloog
make && make install
- gcc安装
tar xzf gcc-4.9.3.tar.gz
cd gcc-4.9.3
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib:/usr/local/isl/lib:/usr/local/cloog/lib
./configure --prefix=/usr/local/gcc --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc --with-isl-include=/usr/local/isl/include --with-isl-lib=/usr/local/isl/lib --with-cloog-include=/usr/local/cloog/include --with-cloog-lib=/usr/local/cloog/lib --disable-multilib --enable-languages=c,c++ --disable-multilib
make && make install
最后将其链接到执行目录
cd /usr/bin
mv gcc gcc4.4.7
mv g++ g++4.4.7
ln -s /usr/local/gcc/bin/gcc gcc
ln -s /usr/local/gcc/bin/g++ g++
碰到一些问题,可以在这里面解决 https://blog.51cto.com/2716255/1965617
对应的版本号问题看这个:https://blog.youkuaiyun.com/xiexievv/article/details/50620170
ps:
gcc的安装需要依赖g++,安装之前最好核对以下是否有g++,没有的话就yum安装一下;
yum install gcc-c++
conda 环境移动
conda create -n insightface --clone path/to/insightface --offline