Rachel
Rachel

Reputation: 117

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. I have also installed miniconda. Whether I run the command:

$python -V

in my home directory, or a specific project directory, the output is Python 2.7.10. Why isn't it Python 3.6, and how can I change this default?

Upvotes: 2

Views: 1613

Answers (2)

Dan Lowe
Dan Lowe

Reputation: 56627

Really it depends on the system what the behavior is. See PEP 394 for more, but roughly speaking,

  • python2 should always point you to Python 2.x
  • python3 should always point you to Python 3.x
  • python on most distributions today will point to Python 2.x
  • Except on a few, it points to Python 3.x now
  • And on a given system python might be overridden to point to Python 3.x
  • And in a virtualenv / venv, python can point to either, depending how it was set up

So in other words, if you want to not really worry about it, use python2 and python3 commands instead of python.

Although, macOS violates this pattern by installing python without a python2 link (there is a python2.7 link, though).

Upvotes: 2

m.rp
m.rp

Reputation: 748

Probably what happened is that you have 2 versions of Python in your environment:

  • 3.6 that you installed manually
  • 2.7.10 installed by 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.

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.

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.

More info on managing virutal environments:

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

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

Upvotes: 2

Related Questions