Anaconda Runtime Error: Python is not installed as a framework?

41,755

Solution 1

If you experience this error, don't forget to check your bash_profile.

You can do this in terminal by:

cd

then

nano .bash_profile

check the contents. Macports and Homebrew add their own headings for things they've done here. You can remove the declarations they make to $PATH. Just leave the one Anaconda has made. I had a If you would like, you can:

cp .bash_profile ./bash_profile_backup_yyyy_mm_dd 

and have a backup of the file, with filename indexing to the date you changed it. That is, provided you actually put in the date in instead of just the formatting characters I'm suggesting.

source ~/.bash_profile

will refresh your system's reference to the bash_profile and you should be good to go in importing and using matplotlib

Solution 2

Posting since I just had this issue and this was a quick fix:

If you used pip to install:

  1. Create ~/.matplotlib/matplotlibrc

  2. Add "backend: TkAgg" (without the quotations) to the file.

Solution 3

I was having the same problem with anaconda 2 & matplotlib 1.5.3.

Running a simple conda install matplotlib to reinstall matplotlib did the trick for me.

Solution 4

If the problem is only matplotlib, is worth try to change the backend:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [4, 5, 6])
plt.show()

If it works you can change the backend permanently from the matplotlibrc file.

Solution 5

I was having the same problem. Installing an older version of matplotlib did the trick for me. Try this command in your terminal while in your virtual environment:

pip install matplotlib==1.4.3
Share:
41,755
Mark Brown
Author by

Mark Brown

Just a dude who likes code

Updated on January 25, 2020

Comments

  • Mark Brown
    Mark Brown over 4 years

    I've installed Anaconda with the pkg installer:

    Python 2.7.10 |Continuum Analytics, Inc.| (default, May 28 2015, 17:04:42) 
    [GCC 4.2.1 (Apple Inc. build 5577)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://binstar.org
    

    but when I attempt to use anything from matplotlib, i.e.:

     from matplotlib import pyplot as plt
    

    I get

    RuntimeError: Python is not installed as a framework.
    The Mac OS X backend will not be able to function correctly if Python is not installed 
    as a framework. See the Python documentation for more information on installing Python 
    as a framework on Mac OS X. Please either reinstall Python as a framework,
    or try one of the other backends.
    

    I'm really not sure what this means, or how to go about fixing it.

  • Mark Brown
    Mark Brown over 8 years
    Good instructions. Even if inside a virtualenv, conflicts from other installations may still exist. Be sure to check the .bash_profile for $PATH declarations if you have the troubles I mentioned
  • John Morrison
    John Morrison over 8 years
    For Anaconda the .bash_profile should have the following: export PATH="/Users/username/anaconda/bin:$PATH"
  • Mark Brown
    Mark Brown about 8 years
    Glen, installing an older version of the library may have solved the issue for you, but the conflicting PATH set by mac ports/Homebrew is what was causing the error for me. I have since put a little more effort into envs
  • linello
    linello over 7 years
    Works on OSX 10.11 El Capitan too
  • SeF
    SeF about 7 years
    Actually, if you want to use this backend by default, follow the instruction of the main answer of stackoverflow.com/questions/21784641/…
  • Mark Brown
    Mark Brown about 6 years
    In this case, that’s not the solution. The conflicting path declarations from MacPorts and homebrew we’re responsible.
  • jhpratt
    jhpratt about 6 years
    Can you provide an explanation of what the difference is?
  • Mark Brown
    Mark Brown about 6 years
    Note: this post had macos in the tags. I presume running under a different env is the solution running the script with pythonw achieves, though isn't an answer that promotes python literacy.
  • user3391229
    user3391229 over 5 years
    this worked for me if I was using a conda environment but not if I was using a virtualenv environment.
  • F Lekschas
    F Lekschas about 5 years
    At least for me, this also worked when matplotlib was installed with conda and not just pip.
  • Casimir
    Casimir about 5 years
    Why doesn't matplotlib do this automatically?
  • John Carrell
    John Carrell about 5 years
    Just for posterity can someone please explain what changing the "backend" does as well as what it means for Python to be installed "as a framework?" Oddly, I couldn't find a succinct answer to this on the web anywhere.
  • Evgenii
    Evgenii over 3 years
    Works on Catalina