一、更新树莓派系统
sudo apt-get update
sudo apt-get upgrade
二、安装python需要的依赖
sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev
sudo apt-get install libffi-dev
三、下载Python的源代码并解压
cd /usr/local/src
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
tar zxvf Python-3.7.4.tgz
四、配置、编译、安装
sudo mkdir /usr/local/python
sudo ./configure --prefix=/usr/local/python
sudo make
sudo make install
报错
ModuleNotFoundError: No module named '_ctypes'
sudo apt-get update
sudo apt-get install libffi-dev
五、创建符号链接
sudo ln -s /usr/local/python/bin/python3 /usr/bin/python
sudo ln -s /usr/local/python/bin/python3 /usr/bin/python3
sudo ln -s /usr/local/python/bin/pip3 /usr/bin/pip
sudo ln -s /usr/local/python/bin/pip3 /usr/bin/pip3
如果提示已经存在
rm /usr/bin/python rm /usr/bin/python3 rm /usr/bin/pip rm /usr/bin/pip3
问题1 报错pip
1安装更新修复
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
sudo python get-pip.py
2测试
- 运行
python3 -m pip --version
以查看是否安装了 pip。 - 如果是,运行
python3 -m pip install --upgrade pip
。 - 如果没有,运行
sudo apt-get install python3-pip
,然后再做一次。
3 还是不行修改
#!/usr/local/python/bin/python3.7 # -*- coding: utf-8 -*- import re import sys #from pip._internal import main from pip import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(main())
修改
#from pip._internal import main from pip import main
问题2 thonny软件无法使用
导致树莓派自带的thonny无法正常用,卸载重装
sudo apt autoremove thonny
安装
sudo apt install thonny