3

I am using Mountain Lion. I have installed python 3.3 and also have python 2.7. I used homebrew.

When opening python, I get:

Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information.

I tried doing this:

brew switch python3 3.3.0.

Still didn't work. Any ideas?

suci
  • 178
  • 7
cryp
  • 2,285
  • 3
  • 26
  • 33

2 Answers2

8

First, your observation

I tried doing this:

brew switch python3 3.3.0.

Still didn't work. Any ideas?

is not a bug, it's a feature. Homebrew's idea is to allow Python 2.7.x and 3.x to live side-by-side. Obviously, the can't both be python, so Python 3 is python3. With the switch command, you just switch which version of brew's python3 package you are using (i.e. your python3 will point to Python 3.3.0), but it does nothing for the Mac or your paths. Now, all the brewed binaries are symlinks in /usr/local/bin, so theoretically you could change all the python symlinks by hand to point to python3 instead of Python 2. I do not recommend that, though, as it will probably break homebrew completely, or will be reverted by future Python updates.

Instead, use the excellent virtualenv: "http://www.virtualenv.org/".

  1. Install it: pip3 install virtualenv

  2. You will see the message "Installing virtualenv script to /usr/local/share/python3", so add this to your PATH.

  3. If you call virtualenv without any parameter, you will get a help message. Among other things, you will see:

    -p PYTHON_EXE, --python=PYTHON_EXE The Python interpreter to use, e.g., --python=python2.5 will use the python2.5 interpreter to create the new environment. The default is the interpreter that virtualenv was installed with (/usr/local/Cellar/python3/3.3.0/bin/python3.3)

So you're lucky, the python you want is already the default. So

  1. virtualenv myproject
  2. cd myproject
  3. source bin/activate
  4. python

    Python 3.3.0 (default, Mar 18 2013, 16:59:10) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.24)] on darwin

Does this help, or can you not use virtualenv for some reason?

If virtualenv is not an option and you definitely want Python 3 and only Python 3 for all your Python needs on your Mac, you might consider not using the homebrewed python, but rather installing the python.org distribution.

lutzh
  • 4,917
  • 1
  • 18
  • 21
0

Your environment is still referencing the default python version that comes pre-installed with Mac OS.

Depending on where either python is installed, you might want to set different paths for the different python installs. Look at these links for more information:

Community
  • 1
  • 1
  • I tried changing the python link in the .bash_profile file. But that didnt work. Even this dindt work: defaults write com.apple.versioner.python Version 2.6. i can access python by just saying python3 but how do I make it default – cryp Feb 25 '13 at 21:10
  • @ashish Try this: http://stackoverflow.com/questions/6998545/how-can-i-make-python-2-6-my-default-in-mac-os-x-lion –  Feb 25 '13 at 21:13
  • hi Kata. Still Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43) – cryp Feb 25 '13 at 21:30
  • What makes you think that it is the Mac OS System Python? I think it looks like homebrew alright. Also, I think Mac OS included Python is at 2.7.2 – lutzh Mar 19 '13 at 09:17