简体   繁体   English

Python:别名为 python3

[英]Python: aliased to python3

I tried to upgrade python 2.7 to python 3 and I modified the file ~/.bash_aliases but when I type python in elementary terminal I get this error我尝试将 python 2.7 升级到 python 3 并修改了文件~/.bash_aliases但是当我在基本终端中键入 python 时出现此错误

zsh: command not found: python3

and when I type which python当我输入 which python

python: aliased to python3

actually I prefer return to python 2.7 or if someone know how can I fix this:c实际上我更喜欢返回 python 2.7 或者如果有人知道我该如何解决这个问题:c

Go into your .zshrc file. 进入您的.zshrc文件。 Is there a line that reads: 是否有一行显示为:

alias python='python3'

If so, remove that line. 如果是这样,请删除该行。 Else, check if you can run python2 , python2.7 , or something like that. 否则,检查是否可以运行python2python2.7或类似的东西。 If so, then just hack and add the line 如果是这样,那么只需修改并添加行

alias python='python2'

Or whatever your python2 is. 或无论您的python2是什么。 Else, type 否则,输入

sudo apt-get install python2.7

Or whatever is the appropriate method for installing programs on your system. 或在系统上安装程序的适当方法是什么。

Follow this steps if you are using macOS.如果您使用的是 macOS,请按照以下步骤操作。

  1. Install Python with brew: brew install python .使用 brew 安装 Python: brew install python This will install the latest version of Python. If you want Python 2.7, do well to specify the version.这将安装最新版本的Python。如果您想要Python 2.7,请指定版本。
  2. Check the path where this Python was installed: brew info python .检查此 Python 的安装路径: brew info python You will see a path similar to: /usr/local/opt/python@3.9/libexec/bin您将看到类似于以下的路径: /usr/local/opt/python@3.9/libexec/bin
  3. Make home brew Python default:让家酿 Python 默认:
$ echo 'export PATH="/usr/local/opt/python@3.9/libexec/bin:$PATH"' >> ~/.zshrc
  1. Source the file to apply changes without restarting the terminal: source ~/.zshrc获取文件以在不重新启动终端的情况下应用更改: source ~/.zshrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM