1

I've installed Python 2.7 using macports and because of my $PATH variable, that's the one I get when I type $ python. However, virtualenv defaults to using Python 2.6 unless I remember to force it to do otherwise with the -p flag.

On a related note, globally running yolk -l shows the following:

Python          - 2.6.1        - active development (/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload)

So my question is, should I do something to ensure the system is always using MacPorts' Python 2.7 or is it not worth worrying that Apple's Python 2.6.1 is apparently in the mix?

wmfox3
  • 2,141
  • 4
  • 21
  • 28

2 Answers2

2

If you force python 2.7 globally on your system, things will break. You don't want to do that.

You should use virtualenvwrapper. It should choose your preferred python.

http://www.doughellmann.com/docs/virtualenvwrapper/install.html#python-interpreter-virtualenv-and-path

Paul McMillan
  • 19,693
  • 9
  • 57
  • 71
  • Hmmm. Getting an error: $ source /usr/local/bin/virtualenvwrapper.sh Traceback (most recent call last): File "", line 1, in ImportError: No module named virtualenvwrapper.hook_loader virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/opt/local/bin/python and that PATH is set properly. – wmfox3 May 28 '11 at 04:07
1

I have had similar problems, although not related specifically to virtualenv. I found that, after installing a particular version of python with macports, and having that version set as default, installing 3rd party modules that are build on or use python using macports solved all problems. You essentially end up with parallel builds, on top of different versions of python. I have a few, and switch between them using python_select. Also, see here on SO for how to get easy_install to work with your new python.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • Great suggestion, juanchopanza. Do you happen to know the current equivalent of python_select -l since I'm now having to use sudo port select python to switch between versions with macports? – wmfox3 May 29 '11 at 13:15
  • I use `python_select`, which I had to get from macports. To change versions, I do need `sudo`, since it sets it as default for all users. – juanchopanza May 29 '11 at 13:47
  • I believe python_select has been deprecated in macports. http://stackoverflow.com/questions/118813/how-do-i-uninstall-python-from-osx-leopard-so-that-i-can-use-the-macports-version/6166416#6166416 – wmfox3 May 29 '11 at 15:52
  • You seem to be right, I didn't know that. After some experimentation, is seems `port select --list python` is a good alternative to `python_select -l`. – juanchopanza May 29 '11 at 20:28