如何在Raspberry Pi中更改默认的python版本 [英] How to change the default python version in Raspberry Pi
问题描述
一天前,我重新安装了Raspberry Pi OS Buster,然后按照本教程在Raspberry pi中安装了Python3.8. https://installvirtual.com/how-to-install-python-3-8-on-raspberry-pi-raspbian/
One day ago I did a fresh installation of Raspberry Pi OS Buster and after that I installed Python3.8 in my Raspberry pi following this tutorial. https://installvirtual.com/how-to-install-python-3-8-on-raspberry-pi-raspbian/
我在bashrc中添加了python别名.
I added python alias to bashrc.
echo "alias python=/usr/local/bin/python3.8" >> ~/.bashrc
source ~/.bashrc
现在在终端中键入 python
,显示 Python 3.8.0(默认值,2020年6月8日,13:17:16)
Now typing python
in terminal showing Python 3.8.0 (default, Jun 8 2020, 13:17:16)
但是当我运行python3时,它显示的是Python Python 3.7.3
But when I run python3 it's showing Python Python 3.7.3
我在上面的命令中添加了指向python3.8的python3别名,但还是没有运气.来自Geany的程序仍显示3.7.我将Geany的bulid命令更改为python(因为我将默认python设置为3.8)
I added python3 alias pointing to python3.8 follwing above commands but still no luck. Programs from Geany still showing 3.7. I changed Geany's bulid commands to python(as I set default python to 3.8)
#!/usr/local/bin/python3.8
import sys
print("Python version")
print (sys.version)
Python版本3.7.3(默认,2019年12月20日,18:57:59)
Python version 3.7.3 (default, Dec 20 2019, 18:57:59)
我有两个问题:
-
如何在Python3.8中运行程序?
How to run programs in Python3.8?
我可以卸载python3.7吗?
Can I uninstall python3.7?
推荐答案
对于那些喜欢直接使用文件系统的人,这是我所做的:
For those of you who like working directly with the filesystem, here is what I did:
- 类型:sudo rm/usr/bin/python
- 类型:sudo ln -s/usr/bin/python3/usr/bin/python
- 类型:ls -l/usr/bin/python
- lrwxrwxrwx 1根根18 Jan 18 11:04/usr/bin/python->/usr/bin/python3
- Python 3.7.3
- 类型:sudo update-alternatives --config python
- 就我而言,找不到其他选择...
在处理过程中,将pip默认值更改为pip3,过程略有不同...
While you are at it, change pip default to pip3, slightly different process...
- 类型:sudo mv/usr/bin/pip/usr/bin/pip2#重命名
- 类型:sudo ln -s/usr/bin/pip3/usr/bin/pip
- 类型:ls -l/usr/bin/pip
- lrwxrwxrwx 1根根18 Jan 18 11:19/usr/bin/pip->/usr/bin/pip3
- /usr/lib/python3/dist-packages/pip(python 3.7)中的pip 18.1
- 注意:切换到默认的python3会使pip2感到困惑,因为它以#!/usr/bin/python 开头
这篇关于如何在Raspberry Pi中更改默认的python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!