0

We're building code that we want to run on both Python 2 & 3. It uses matplotlib. My local machine runs OS X Yosemite.

The matplotlib installation documentation provides instructions for both python 2 & 3, but implies that both cannot be supported on a single Mac. Is this true, and if not how can both be supported with matplotlib?

(Parenthetically, I know that separate installations can be made with virtual environments or machines. However, I've found these cumbersome on Macs. On the other hand, I'm also testing builds on a commercial cloud-based build tester that uses separate VMs for each configuration, which works reasonably well.)

Arthur
  • 525
  • 7
  • 18
  • 1
    `but implies that both cannot be supported on a single Mac` - can you quote the passage where you found that? – cel Sep 11 '16 at 14:27
  • Use miniconda for environment management. It's really easy to install and use, you can create Py2 and Py3 environments. You can certainly have matplotlib for 2 and 3 in the same Mac, I have that cause I'm developing a Python library that depends on matplotlib and supports both Python versions – Eduardo Sep 11 '16 at 14:29
  • @cel: The 'or' in "or (Python 3)" carries that implication. – Arthur Sep 12 '16 at 17:17

2 Answers2

1

I too find virtualenvs annoying for this sort of thing, and have run into strange issues on OSX virutalenvs with matplotlib in particular. But there is a really nice tool for supporting parallel installations of different package & python versions: conda. It will manage parallel environments with any Python version; for your case you can do the following:

  1. Install miniconda

  2. Create a Python 3 environment: conda create -n py3env python=3.5 matplotlib

  3. Create a Python 2 environment: conda create -n py2env python=2.7 matplotlib

  4. Activate the one you want with, e.g. source activate py2env

And you're ready to go. For more information on conda environments, see the conda-env docs.

jakevdp
  • 77,104
  • 11
  • 125
  • 160
0

This appears to work:

python 3: install https://www.python.org/ftp/python/3.5.2/python-3.5.2-macosx10.6.pkg

curl -O https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip3 install nose
pip3 install matplotlib
pip3 install cobra
pip3 install numpy
pip3 install scipy
pip3 install openpyxl
pip3 install future
pip3 install recordtype
pip3 install lxml
pip3 install python-libsbml

python 2: install https://www.python.org/ftp/python/2.7.12/python-2.7.12-macosx10.6.pkg

curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
sudo pip2 install nose
sudo pip2 install matplotlib
sudo pip2 install cobra
sudo pip2 install numpy
sudo pip2 install scipy
sudo pip2 install openpyxl
sudo pip2 install future
sudo pip2 install recordtype
sudo pip2 install lxml
sudo pip2 install python-libsbml
sudo pip2 uninstall python-dateutil        # deal with bug in six; see http://stackoverflow.com/a/27634264/509882
sudo pip2 install python-dateutil==2.2
Arthur
  • 525
  • 7
  • 18
  • I'd really recommend against ``sudo pip install``ing anything, unless you *really* know what you're doing. Doing this can modify packages on the root python installation for the operating system. On OSX & some linux distros, the OS depends on Python and changing the packages can break parts of the operating system itself. Much better is to use either virtualenvs or (as I mentioned above) conda-envs. – jakevdp Sep 12 '16 at 21:59