简体   繁体   English

当我在终端输入'python -V'时......为什么我会看到Python 2.7.10

[英]When I type 'python -V' in my terminal…why do I see Python 2.7.10

I have only installed Python3.6 on my Mac. 我只在我的Mac上安装了Python3.6。 I have also installed miniconda. 我也安装了miniconda。 Whether I run the command: 我是否运行命令:

$python -V $ python -V

in my home directory, or a specific project directory, the output is Python 2.7.10. 在我的主目录或特定的项目目录中,输出是Python 2.7.10。 Why isn't it Python 3.6, and how can I change this default? 为什么不是Python 3.6,我该如何更改此默认值?

Probably what happened is that you have 2 versions of Python in your environment: 可能发生的事情是你的环境中有2个版本的Python:

  • 3.6 that you installed manually 3.6你手动安装
  • 2.7.10 installed by miniconda 2.7.10由miniconda安装

For some reason the environment variable for the python command is set to the 2.7.10 one, so in your shell the python command refers to the 2.7 version, if you want it to point to the 3.6 one you need to update the path variable for the python command. 由于某种原因,python命令的环境变量设置为2.7.10,所以在你的shell中python命令引用2.7版本,如果你想要它指向你需要更新路径变量的3.6版本python命令。

If you want to manage more environments i suggest you to use Anaconda/miniconda and setting up virtual environments for both python 2 and 3, so you can switch between the two. 如果你想管理更多环境,我建议你使用Anaconda / miniconda并为python 2和3设置虚拟环境,这样你就可以在两者之间切换。

If you are only interested in one version of python either use a conda distribution or plain Python, as mixing things often creates this kind of problems. 如果您只对一个版本的python感兴趣,请使用conda发行版或普通Python,因为混合使用通常会产生这种问题。

More info on managing virutal environments: 有关管理虚拟环境的更多信息:

Python: http://docs.python-guide.org/en/latest/dev/virtualenvs/ Python: http//docs.python-guide.org/en/latest/dev/virtualenvs/

Anaconda: https://conda.io/docs/user-guide/tasks/manage-environments.html Anaconda: https//conda.io/docs/user-guide/tasks/manage-environments.html

Really it depends on the system what the behavior is. 真的,这取决于系统的行为。 See PEP 394 for more, but roughly speaking, 有关详细信息,请参阅PEP 394 ,但粗略地说,

  • python2 should always point you to Python 2.x python2应该始终指向Python 2.x.
  • python3 should always point you to Python 3.x python3应该始终指向Python 3.x.
  • python on most distributions today will point to Python 2.x 今天大多数发行版上的python都将指向Python 2.x.
  • Except on a few, it points to Python 3.x now 除了少数,它现在指向Python 3.x.
  • And on a given system python might be overridden to point to Python 3.x 在给定的系统上, python可能会被覆盖以指向Python 3.x.
  • And in a virtualenv / venv, python can point to either, depending how it was set up 在virtualenv / venv中, python可以指向其中任何一个,具体取决于它的设置方式

So in other words, if you want to not really worry about it, use python2 and python3 commands instead of python . 换句话说,如果你不想真的担心它,使用python2python3命令而不是python

Although, macOS violates this pattern by installing python without a python2 link (there is a python2.7 link, though). 虽然,macOS通过安装没有python2链接的python违反了这种模式(但是有一个python2.7链接)。

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

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