ubuntu安装python3(源码安装方法)

2022-09-10 09:04:13 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

Ubuntu安装Python3

一、安装相关依赖

代码语言:javascript复制
apt-get update && apt-get upgrade
apt-get install -y build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
apt-get dist-upgrade
apt-get install -y build-essential python-dev python-setuptools python-pip python-smbus
apt-get install -y build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev wget

二、源码安装

代码语言:javascript复制
# 下载链接
wget https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tgz
# 解压
tar zxvf Python-3.9.8.tgz -C /usr/local
cd /usr/local/Python-3.9.8
# 配置
./configure prefix=/usr/local/python3 --enable-optimizations
# 编译
make && make install

三、配置系统环境

代码语言:javascript复制
# 删除之前的python3
whereis python
#(有风险)* rm -rf 所有python3的版本(除去/usr/local/python3) 
# 删除之前软连接
rm -rf /usr/bin/python
rm -rf /usr/bin/pip
# 添加新的链接
cp /usr/local/python3/lib/libpython3.9.a /usr/lib
echo "/usr/lib" > /etc/ld.so.conf.d/python3.9.conf
ldconfig
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
# 添加环境变量
vi /etc/profile
#
# 添加 export PATH=$PATH:/usr/local/python3/bin
#
source /etc/profile

四、测试

代码语言:javascript复制
python -V
pip -V
pip list
python -m pip install --upgrade pip

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152407.html原文链接:https://javaforall.cn

0 人点赞