Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv virtualenv not work for matplotlib #140

Closed
shixudongleo opened this issue Jan 10, 2016 · 5 comments
Closed

pyenv virtualenv not work for matplotlib #140

shixudongleo opened this issue Jan 10, 2016 · 5 comments

Comments

@shixudongleo
Copy link

I installed a framework enable python 2.7.8. And matlablib is working fine under this python 2.7.8.
After that, I created a virtualenv, matplotlib is not working inside the virtualenv.

A simple test:

$ env PYTHON_CONFIGURE_OPTS="--enable-framework --enable-ipv6 --enable-unicode --with-threads" pyenv install 2.7.8
$ pyenv shell 2.7.8
$ pip install numpy scipy matplotlib
$ python -c "import matplotlib.pyplot as plt" #this works 
$ pyenv virtualenv 2.7.8 nipype_env
$ pyenv activate nipype_env
$ pip install numpy scipy matplotlib
$ python -c "import matplotlib.pyplot as plt" #this doesnot work
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/shixudongleo/.pyenv/versions/nipype_env/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/shixudongleo/.pyenv/versions/nipype_env/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Users/shixudongleo/.pyenv/versions/nipype_env/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
    from matplotlib.backends import _macosx
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. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

I am new in using pyenv and pyenv virtualenv. In previous experience with virtualenv, I have not encounter such a problem.

I have found differences in directory structure between 2.7.8 and nipype_env.

$ ls ~/.pyenv/versions/2.7.8
Python.framework envs             lib
bin              include          share
$ ls ~/.pyenv/versions/nipype_env
bin                lib                share
include            pip-selfcheck.json

I have found a fix in this link. But I am still wondering whether there is a more elegant way support by pyenv virtualenv to fix my problem.

@twoframesperminute
Copy link

Matplotlib expects a Framework install on OS X in order to manipulate GUI elements. You can install Framework versions with a command like this:

env PYTHON_CONFIGURE_OPTS="--enable-framework CC=clang" pyenv virtualenv <python_version> <env_name>

The fact that it worked in your first example is because you used --enable-framework.

@yyuu
Copy link
Collaborator

yyuu commented Jan 21, 2016

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. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

Read error messages.

@brifordwylie
Copy link

brifordwylie commented Sep 4, 2018

I had to do something a bit different in order to get my pyenv virtualenv to work.

  1. Run @psomhorst suggested config opt on the ^base^ python (in my case 3.6.6)

    $ env PYTHON_CONFIGURE_OPTS="--enable-framework CC=clang" pyenv install 3.6.6
    
  2. Uninstall my virtualenv (if you already have one that you want to reuse)

    $ pyenv uninstall py3
    
  3. Reinstall my virtualenv

    $ pyenv virtualenv 3.6.6 py3
    

And then of course activate my virtualenv like normal.. and then everything worked great.

@keisuke-nakata
Copy link

a simple solution (and seem the most elegant for me) is putting matplotlibrc at your config dirctory (config dir depends on how matplotlib prioritizes its rcfile. see https://matplotlib.org/users/customizing.html) and set backend: Agg.

@jwuttke
Copy link

jwuttke commented Jan 30, 2024

For reference: After installing Tk to the computer it is necessary to rerun pyenv install <version>. It is not necessary to uninstall and reinstall pyenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants