Linux 如何使 python3.2 解释器成为 debian 中的默认解释器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10434260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make python3.2 interpreter the default interpreter in debian
提问by Shankar Menon
I got both python2 and python3 installed in my debian machine. But when i try to invoke the python interpreter by just typing 'python' in bash, python2 pops up and not python3. Since I am working with the latter at the moment, It would be easier to invoke python3 by just typing python. Please guide me through this.
我在我的 debian 机器上安装了 python2 和 python3。但是当我尝试通过在 bash 中键入“python”来调用 python 解释器时,会弹出 python2 而不是 python3。由于我目前正在使用后者,因此只需键入 python 来调用 python3 会更容易。请指导我完成这个。
采纳答案by mata
the only somehow safe way would be to use an alias in your shell, by placing
唯一安全的方法是在 shell 中使用别名,通过放置
alias python=python3
into your ~/.profile
or ~/.bashrc
...
进入您的~/.profile
或~/.bashrc
...
this way the system scripts depending on python being python2 won't be affected.
这样依赖于 python 的系统脚本是 python2 不会受到影响。
回答by nkh
Well, you can simply create a virtualenv
with the python3.x using this command:
好吧,您可以virtualenv
使用以下命令简单地使用 python3.x创建一个:
virtualenv -p <path-to-python3.x> <virtualenvname>
virtualenv -p <path-to-python3.x> <virtualenvname>
回答by 01010100
using command:
使用命令:
update-alternatives --config python
Might Work However On My System(I have Python2&3 Installed As Well) It Gives Me An Error Saying No Alternatives For Python...
但是可能在我的系统上工作(我也安装了 Python2 和 3)它给了我一个错误,说没有 Python 的替代品......
回答by user2533809
btw, if you are using bash or running from the shell, and you normally include at the top of the file the following line:
顺便说一句,如果您使用 bash 或从 shell 运行,并且通常在文件顶部包含以下行:
#!/usr/bin/python
#!/usr/bin/python
then you can change the line to instead be:
那么您可以将行更改为:
#!/usr/bin/python3
#!/usr/bin/python3
That is another way to have pythonXrun instead of the default (where Xis 2 or 3).
这是让 python X运行而不是默认运行的另一种方式(其中X是 2 或 3)。
回答by Yajo
Others have adviced you about the possible drawbacks, so, on the issue at hand:
其他人已经就可能的缺点向您提出了建议,因此,关于手头的问题:
ln -s $(which python3) /usr/local/bin/python