可乐博客

Centos7下 Python3.7安装与Pyinstaller打包

一般直接安装与打包是不成功的,所以记录一下
注释指令的请在谷歌后尝试

#yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
#yum search python3 | grep devel 
#yum install -y python3-devel.x86_64

#安装centos7开发工具包
yum -y groupinstall "Development tools"
#安装python需要的一些必要库、常用、可能会用到的库
yum install -y lrzsz wget curl gcc make openssl openssl-devel openssl-static bzip2 bzip2-devel zlib-devel ncurses ncurses-devel readline readline-devel xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel expat-devel tk tk-devel tcl tcl-devel libffi libffi-devel libpcap-devel

#tar xzf Python-3.7.4.tgz -C /tmp
#tar xzf Python-3.7.4.tgz
#在下面这个网站下了一个python37-devel 3.7的rc1版本 其他版本自测
#wget http://macports.mirror.ac.za/distfiles/python37-devel/Python-3.7.0rc1.tar.xz
#解压后可以删除压缩包,建议留一个
tar -xvf Python-3.7.0rc1.tar.xz
#rm -f Python-3.7.4.tgz
cd Python-3.7.0rc1

#几种不同的配置,--enable-shared是必要的,可以把devel里面的库拷贝到python lib文件夹里面。--enable-optimizations是优化python代码的,怎么优化的自己谷歌
#./configure --prefix=/usr/local/python-3.7.0
#./configure --enable-shared --prefix=/usr/local/python-3.7.0
./configure --enable-shared --enable-optimizations --prefix=/usr/local/python-3.7.0
#./configure --enable-shared --enable-optimizations --without-ensurepip --prefix=/usr/local/python3.7.0

make
#这两个有区别 选一种就可以
#make altinstall
make install

#如果pip坏了就重新安装
#wget https://bootstrap.pypa.io/get-pip.py
#/usr/local/python3.7.0/bin/python3.7 get-pip.py

#把python3.7-devel库拷贝到系统库,不然python打不开,pyinstaller编译不了
cp /usr/local/python-3.7.0/lib/libpython3.7m.so.1.0 /usr/lib64

#pip换清华源,pip能快很多
#~/.pip/pip.conf
mkdir -p ~/.php/
cat>~/.pip/pip.conf<<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
EOF
#升级pip,给python加个快捷方式,以后在任意位置直接python3和pip就好使
/usr/local/python-3.7.0/bin/pip3.7 install --upgrade pip
ln -s /usr/local/python-3.7.0/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python-3.7.0/bin/pip /usr/bin/pip

#其实这里就可以虚拟环境了
#pip install pyenv

#pip就可以正常使了
pip install aiofiles
pip install aiohttp
pip install tqdm

#pip 安装 pyinstaller,设置软路由
pip install pyinstaller
ln -s /usr/local/python-3.7.0/bin/pyinstaller /usr/bin/pyinstaller


参考网站
Centos7安装python3.7及PyInstaller打包

技术