安装依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
下载python3.6.8
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
解压
tar -zxvf Python-3.6.8.tgz
创建安装目录
mkdir /usr/local/python3
编译安装
./configure --prefix=/usr/local/python3
make
make install
上面几个语句单独执行
旧python改名
mv /usr/bin/python /usr/bin/python_bak
mv /usr/bin/pip /usr/bin/pip_bak
加软链接指向新的python
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
检查python版本
python -V
pip3加入环境变量
目前pip3不能使用,需要将/usr/local/python3/bin加入PATH
vim ~/.bash_profile
修改后如下:
.bash_profile
#Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
复制代码
保存退出后,执行以下命令,让上一步修改成功
source ~/.bash_profile
修改yum的python库
由于yum是py2写的,所以更换完python路径后,yum可能会出现错误
所以要修改配置文件
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down
把第一行python改为python2
pip升级
pip3 install --upgrade pip
安装python库
根据自己需求安装
安装uwsgi,以及运行
pip3 install uwsgi
# 加软链接
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
# 连行
uwsgi uwsgiconfig.ini
注意,uwsgi配置多进程的情况下,要考虑内存是否够用,每个进程都需要实例化一次。
opencv缺少文件错误
ImportError: libXext.so.6: cannot open shared object file: No such file or directory
ImportError: libSm.so.6: cannot open shared object file: No such file or directory
安装对应的库:
yum -y install libSM-1.2.2-2.el7.x86_64 --setopt=protected_multilib=false
yum -y install libXext-1.3.3-3.el7.x86_64 --setopt=protected_multilib=false
报错ImportError: libGL.so.1: cannot open shared object file
安装库:
yum -y install mesa-libGL.x86_64