赞
踩
对于全新的Ubuntu系统,需要先把必要的库安装准备好,这样编译安装Python3.7的时候不容易报错
最常见的就是ModuleNotFoundError: No module named '_ctypes'
,原因是在3.7
中,ctypes模块依赖libffi-dev
库
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
tar -zxvf Python-3.7.7.tgz
"–enable-optimizations"这个参数会启用配置文件引导的优化(PGO)和链接时间优化(LTO), 可以不加
cd Python-3.7.7
./configure --enable-optimizations --prefix=/opt/python37
这个用的时间会比较长,请耐心等待
sudo make && make install
sudo ln -s /opt/python37/bin/python3.7 /usr/bin/python3.7
注册 /usr/bin/python3.7 到 /usr/bin/python3这个链接上,名称为python3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
选择默认配置的python3
sudo update-alternatives --config python3
python3.7 -V
cd ..
sudo rm -rf Python-3.7.7.tgz
sudo rm -rf Python-3.7.7
ModuleNotFoundError: No module named '_ctypes'
的解决办法
sudo apt-get install libffi-devel
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。