@@ -8,7 +8,7 @@ Working with Matplotlib in Virtual environments
88 :backlinks: none
99
1010
11- .. _ introduction :
11+ .. _ virtualenv_introduction :
1212
1313Introduction
1414============
@@ -25,6 +25,9 @@ If you only use the ``IPython/Jupyter Notebook``'s ``inline`` and ``notebook``
2525backends and non interactive backends you should not have any issues and can
2626ignore everything below.
2727
28+ If you are using Matplotlib on OSX you may also want to consider the
29+ :ref: `OSX framework FAQ <osxframework-faq >`.
30+
2831GUI Frameworks
2932==============
3033
@@ -59,118 +62,3 @@ Alternatively, you can manually symlink the GUI frameworks into the environment.
5962I.e. to use PyQt5, you should symlink ``PyQt5 `` and ``sip `` from your system
6063site packages directory into the environment taking care that the environment
6164and the systemwide install use the same python version.
62-
63- OSX Framework builds
64- ====================
65-
66- Short version
67- -------------
68-
69- If you are on Python 3, use ``venv `` instead of ``virtualenv ``::
70-
71- python -m venv my-virtualenv
72- source my-virtualenv/bin/activate
73-
74- Otherwise you will need one of the workarounds below.
75-
76- Long version
77- ------------
78-
79- On OSX, two different types of Python Builds exist: a regular build and a
80- framework build. In order to interact correctly with OSX through the native
81- GUI frameworks you need a framework build of Python.
82- At the time of writing the ``macosx `` and ``WXAgg `` backends require a
83- framework build to function correctly. This can result in issues for
84- a python installation not build as a framework. In virtual envs and when
85- using (Ana)Conda. From Matplotlib 1.5 onwards the ``macosx `` backend
86- checks that a framework build is available and fails if a non framework
87- build is found. WX has a similar check build in.
88-
89- Without this check a partially functional figure is created.
90- Among the issues with it is that it is produced in the background and
91- cannot be put in front of any other window.
92-
93-
94- OSX Conda
95- =========
96-
97- The default python provided in (Ana)Conda is not a framework
98- build. However, the Conda developers have made it easy to install
99- a framework build in both the main environment and in Conda envs.
100- To use this install python.app ``conda install python.app `` and
101- use ``pythonw `` rather than ``python ``
102-
103-
104- OSX virtualenv
105- ==============
106-
107- Unfortunately virtualenv creates a non
108- framework build even if created from a framework build of Python.
109-
110- The issue has been reported on the virtualenv bug tracker `here
111- <https://github.com/pypa/virtualenv/issues/54> `__ and `here
112- <https://github.com/pypa/virtualenv/issues/609> `__
113-
114- Until this is fixed, one of the following workarounds must be used:
115-
116- ``PYTHONHOME `` Function
117- -----------------------
118-
119- The best known work around is to use the non
120- virtualenv python along with the PYTHONHOME environment variable.
121- This can be done by defining a function in your ``.bashrc `` using
122-
123- .. code :: bash
124-
125- function frameworkpython {
126- if [[ ! -z " $VIRTUAL_ENV " ]]; then
127- PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python " $@ "
128- else
129- /usr/local/bin/python " $@ "
130- fi
131- }
132-
133- This function can then be used in all of your virtualenvs without having to
134- fix every single one of them.
135-
136- With this in place you can run ``frameworkpython `` to get an interactive
137- framework build within the virtualenv. To run a script you can do
138- ``frameworkpython test.py `` where ``test.py `` is a script that requires a
139- framework build. To run an interactive ``IPython `` session with the framework
140- build within the virtual environment you can do ``frameworkpython -m IPython ``
141-
142- ``PYTHONHOME `` Script
143- ^^^^^^^^^^^^^^^^^^^^^
144-
145- An alternative work around borrowed from the `WX wiki
146- <http://wiki.wxpython.org/wxPythonVirtualenvOnMac> `_, is to use the non
147- virtualenv python along with the PYTHONHOME environment variable. This can be
148- implemented in a script as below. To use this modify ``PYVER `` and
149- ``PATHTOPYTHON `` and put the script in the virtualenv bin directory i.e.
150- ``PATHTOVENV/bin/frameworkpython ``
151-
152- .. code :: bash
153-
154- #! /bin/bash
155-
156- # what real Python executable to use
157- PYVER=2.7
158- PATHTOPYTHON=/usr/local/bin/
159- PYTHON=${PATHTOPYTHON} python${PYVER}
160-
161- # find the root of the virtualenv, it should be the parent of the dir this script is in
162- ENV=` $PYTHON -c " import os; print(os.path.abspath(os.path.join(os.path.dirname(\" $0 \" ), '..')))" `
163-
164- # now run Python with the virtualenv set as Python's HOME
165- export PYTHONHOME=$ENV
166- exec $PYTHON " $@ "
167-
168- With this in place you can run ``frameworkpython `` as above but will need to add this script
169- to every virtualenv
170-
171- PythonW Compiler
172- ^^^^^^^^^^^^^^^^
173-
174- In addition
175- `virtualenv-pythonw-osx <https://github.com/gldnspud/virtualenv-pythonw-osx >`_
176- provides an alternative workaround which may be used to solve the issue.
0 commit comments