终端仅运行 2.7,即使更改别名后 [英] terminal only running 2.7, even after changing alias
问题描述
如何让终端运行像/manage.py 这样的脚本,它会使用 python3 而不是 python2?如果我输入python",它会运行 python3,但这个命令运行 python2.
How can I get terminal to run a script like /manage.py where it will use python3 instead of python2? If I type 'python' it runs python3, but this command runs python2.
推荐答案
manage.py
的第一行应该是:
#!/usr/bin/env python3
这称为shebang,并根据$PATH
中第一个python 版本告诉您的shell 应使用哪个python 安装.
This is called the shebang and tells your shell which python installation should be used based on which version of python is first in $PATH
.
如果第一行不是 #!/usr/bin/env python3
,它应该是.如果是,您应该将的python3的位置添加到$PATH
.
If the first line isn't #!/usr/bin/env python3
, it should be. If it is, you should prepend the location of python3 to $PATH
.
您需要将以下内容添加到您的 ~/.bashrc
中:
You'll want to do this by adding the following to your ~/.bashrc
:
export PATH="`which python3`:$PATH"
这篇关于终端仅运行 2.7,即使更改别名后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!