树莓派是基于Linux的单片机电脑,由英国树莓派基金会开发,目的是以低价硬件及自由软件促进学校的基本计算机科学教育。Raspberry Pi OS是为树莓派基于Debian开发的操作系统。
首先,可以更新到最新的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
👍
楼主残忍的关闭了评论