首先,可以更新到最新的Raspberry Pi OS。

sudo apt update
sudo apt dist-upgrade
sudo apt clean
sudo reboot

树莓派Raspberry Pi OS预装了python2和3,默认使用python2;要想使用python3,需要使用python3、pip3等指令;或者——

删除python2.7,输入:

sudo apt-get autoremove python2.7

删除链接(有可能已删除):

sudo rm /usr/bin/python
sudo rm /usr/bin/pip

新建链接:

sudo ln -s /usr/bin/python3.7 /usr/bin/python
sudo ln -s /usr/bin/pip3 /usr/bin/pip

查看版本:

python

显示如下:

Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

安装Python 3.8.5

1.更新Raspbian

sudo apt-get update

2.安装依赖项

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

3.下载Python

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz

4.安装Python 3.8

sudo tar zxf Python-3.8.5.tgz
cd Python-3.8.5
sudo ./configure --enable-optimizations
sudo make -j 4
sudo make altinstall

5.将Python 3.8设置为默认版本

echo "alias python=/usr/local/bin/python3.8" >> ~/.bashrc
source ~/.bashrc

6.检查Python版本

python -V
Python 3.8.5

7.清理存档

sudo rm -rf Python-3.8.5.tgz
sudo rm -rf Python-3.8.5

8.可能需要重建链接

sudo ln -s /usr/bin/python3.8 /usr/bin/python


本文由 quaner 整理发布,参考 CC-BY-SA 3.0 协议共享,欢迎转载、引用或改编。
感谢您的支持,以让我们持续关注中国学子的STEAM旅程!

还不快抢沙发

添加新评论