NT_
NT_

Reputation: 641

python versions management: always results python 2.7 in console

Several versions of python are installed on my Mac.

Usually, I am using Anaconda with Python 2.7. Nowadays I decide to try Python 3.6

Environment parameters:

which python
#/Users/User/anaconda/bin/python

which python3.6 
#/usr/local/bin/python3.6

echo $PATH 
/Users/User/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/User/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

The problem is:

~ User$ /usr/local/bin/python3.6 --version
  Python 2.7.14 :: Anaconda, Inc.

How can I to overcome this trouble?

Upvotes: 1

Views: 713

Answers (1)

Taylor D. Edmiston
Taylor D. Edmiston

Reputation: 13024

The output from the second command where running python3.6 --version prints out a Python 2.7.14 string doesn't make sense to me. You might try removing the Anaconda directories from your PATH environment variable and see if that resolves it.

The simplest way to manage and install multiple Python versions is through pyenv.

It allows you to install new versions with pyenv install <version> for dozens of Python versions including CPython as well as alternative interpreters like PyPy.

I would recommend you try installing pyenv:

$ brew install pyenv

Then install Python 3.6.5 via it:

$ pyenv install 3.6.5

You can set this version as your system-wide default Python version as well:

$ pyenv global 3.6.5

Then in projects where you want the python command to point to a Python 2.7 shim, you can set the local version in that directory with:

$ pyenv local 2.7.14

With these commands, you can just run python in any one of your project directories (after you've set a custom override version if desired), and not have to worry about calling python3.6 in some places, python2.7 in others, etc.

In a more advanced setup, you can also provide multiple Python versions if you have a project that needs both Python 2 and Python 3 together, for example, in a shell session:

$ pyenv shell 3.6.5 2.7.14
$ pyenv version
3.6.5 (set by PYENV_VERSION environment variable)
2.7.14 (set by PYENV_VERSION environment variable)
$ python --version
Python 3.6.5
$ python2 --version
Python 2.7.14
$ python3 --version
Python 3.6.5

(In this case whichever version you set first is the one that python points to by default.)

Upvotes: 3

Related Questions