简体   繁体   English

Python2.7 到 Python3 Ubuntu 切换

[英]Python2.7 to Python3 Ubuntu switch

I would like to install graph tool on ubuntu.我想在 ubuntu 上安装图形工具。 Therefore I want to make the default version of python to 3.7 instead of 2.7 because my compiler give me the error, that the python interpreter is to old to run the configure.因此,我想将 python 的默认版本设置为 3.7 而不是 2.7,因为我的编译器给了我错误,即 python 解释器太旧而无法运行配置。

So do u know an solution?那么你知道解决方案吗?

Thanks a lot非常感谢

If you need to execute Python3 when you run the python command, the easiest way to do it is create an alias like this:如果您在运行python命令时需要执行Python3 ,最简单的方法是创建这样的别名:

alias python=python3

But you don't need to mess with it, maybe you can launch the configurations and run programs with python3 command instead of python .但是您不需要弄乱它,也许您可​​以使用python3命令而不是python启动配置并运行程序。

python3 file.py

或者将#!/usr/bin/python3添加到代码的第一行以使用 python 3 自动运行它。

I'll recommend not using aliases nor changing defaults.我建议不要使用别名或更改默认值。 Those things have a way of coming back to bite you later on.那些东西以后有办法回来咬你。

By your description, you said that the tool said the interpreter was too old.根据你的描述,你说工具说解释器太旧了。 I'll guess that it needs a python3 interpreter.我猜它需要一个 python3 解释器。 So what you should do is a simple sudo apt install python3 and use python3 instead of python when running the code from the terminal.所以你应该做的是一个简单的sudo apt install python3并在从终端运行代码时使用python3而不是python

Example:例子:

Instead of python manage.py runserver而不是python manage.py runserver

Do... python3 manage.py runserver做... python3 manage.py runserver

  1. List all the installed versions of Python 3: ls /usr/bin/python3*列出所有已安装的 Python 3 版本: ls /usr/bin/python3*

  2. Add Python 3.7 to the alternatives list and change its priority: sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1将 Python 3.7 添加到替代列表并更改其优先级: sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1

  3. Change the default version of Python by using following command:使用以下命令更改 Python 的默认版本:

    sudo update-alternatives --config python

Type the number of the version you wish to set as default and confirm with enter.输入您希望设置为默认版本的版本号,然后按回车键确认。

  1. Double check, that the change was successfully introduced by: python -V仔细检查,更改是通过以下方式成功引入的: python -V

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

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