分类
python

Ubuntu/Debian/Raspbian源码编译安装Python3.8 及默认版本选择配置

Python 2 即将退出历史舞台,赶紧熟悉python 3的安装及配置吧。

1. 安装编译依赖包

sudo apt update
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev tar wget vim

2.下载python3.8源代码

cd /tmp && wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -zxf Python-3.8.0.tgz
cd Python-3.8.0

3.编译及安装python3.8

./configure --enable-optimizations
make -j 4 #如果你的系统有8核,可以使用-j 8
make altinstall

不要使用标准make来安装,否则会覆盖系统默认的python版本

by ITGeeker

4.python3.8版本确认

python3.8 --version

5.设置python3.8版本为默认版本

python -V #查看当前默认版本
echo "alias python='/usr/local/bin/python3.8'" >> ~/.bashrc #刚刚编译安装目录
source ~/.bashrc
python -V #确认是否已切换成功

echo “alias python=’/usr/bin/python3.7′” >> ~/.bashrc #切换到python3.7 apt安装版本

by ITGeeker
分类
python

升级Python到2.7.15 on CentOS 6 x64

Centos 6 自带的2.6版本队友有些情况总会出现各种错误,例如:

File "/usr/lib/python2.6/site-packages/pip/_internal/index.py", line 526 
{str(c.version) for c in all_candidates}, ^ 
SyntaxError: invalid syntax

明确你的Linux版本

cat /etc/redhat-release

安装依赖:

yum groupinstall -y "Development tools"
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

下载最新版本并编译安装

cd /tmp
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar zxf Python-2.7.15.tgz
cd Python-2.7.15
./configure
make && make install

#新版目录

ll -tr /usr/local/bin/python*

#系统自带老版本目录

ll -tr /usr/bin/python*

备份老版本命令,创建新版本软连接

mv /usr/bin/python /usr/bin/python.old
rm -f /usr/bin/python-config
ln -s /usr/local/bin/python /usr/bin/python && ln -s /usr/local/bin/python-config /usr/bin/python-config && ln -s /usr/local/include/python2.7/ /usr/include/python2.7

检查一下是否正确

python --version

为新版 Python 安装 setuptools

wget https://bootstrap.pypa.io/ez_setup.py -O - | python
easy_install pip

然后就可以pip安装了

pip install itgeeker