@@ -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
@@ -40,8 +43,7 @@ exist. Some of these are given here:
4043* The ``TKAgg `` backend doesn't require any external dependencies and is
4144 normally always available.
4245* The ``QT4 `` framework ``PySide `` is pip installable.
43- * The upcoming `WX Phoenix <http://wiki.wxpython.org/ProjectPhoenix >`_ toolkit
44- is ``pip `` installable.
46+ * ``PYQT5 `` is pip installable on Python 3.5.
4547
4648Other frameworks are harder to install into a virtual environment. There are at
4749least two possible ways to get access to these in a virtual environment.
@@ -58,95 +60,3 @@ Alternatively, you can manually symlink the GUI frameworks into the environment.
5860I.e. to use PyQt5, you should symlink ``PyQt5 `` and ``sip `` from your system
5961site packages directory into the environment taking care that the environment
6062and the systemwide install use the same python version.
61-
62- OSX
63- ===
64-
65- Short version
66- -------------
67-
68- If you are on Python 3, use ``venv `` instead of ``virtualenv ``::
69-
70- python -m venv my-virtualenv
71- source my-virtualenv/bin/activate
72-
73- Otherwise you will need one of the workarounds below.
74-
75- Long version
76- ------------
77-
78- On OSX, two different types of Python Builds exist: a regular build and a
79- framework build. In order to interact correctly with OSX through some
80- GUI frameworks you need a framework build of Python.
81- At the time of writing the ``macosx ``, ``WX `` and ``WXAgg `` backends require a
82- framework build to function correctly. Unfortunately virtualenv creates a non
83- framework build even if created from a framework build of Python. Conda
84- environments are framework builds. From
85- Matplotlib 1.5 onwards the ``macosx `` backend checks that a framework build is
86- available and fails if a non framework build is found.
87- WX has a similar check build in.
88-
89- The issue has been reported on the virtualenv bug tracker `here
90- <https://github.com/pypa/virtualenv/issues/54> `__ and `here
91- <https://github.com/pypa/virtualenv/issues/609> `__
92-
93- Until this is fixed, one of the following workarounds must be used:
94-
95- ``PYTHONHOME `` Script
96- ^^^^^^^^^^^^^^^^^^^^^
97-
98- The best known workaround,
99- borrowed from the `WX wiki
100- <http://wiki.wxpython.org/wxPythonVirtualenvOnMac> `_, is to use the non
101- virtualenv python along with the PYTHONHOME environment variable. This can be
102- implemented in a script as below. To use this modify ``PYVER `` and
103- ``PATHTOPYTHON `` and put the script in the virtualenv bin directory i.e.
104- ``PATHTOVENV/bin/frameworkpython ``
105-
106- .. code :: bash
107-
108- #! /bin/bash
109-
110- # what real Python executable to use
111- PYVER=2.7
112- PATHTOPYTHON=/usr/local/bin/
113- PYTHON=${PATHTOPYTHON} python${PYVER}
114-
115- # find the root of the virtualenv, it should be the parent of the dir this script is in
116- ENV=` $PYTHON -c " import os; print(os.path.abspath(os.path.join(os.path.dirname(\" $0 \" ), '..')))" `
117-
118- # now run Python with the virtualenv set as Python's HOME
119- export PYTHONHOME=$ENV
120- exec $PYTHON " $@ "
121-
122-
123- With this in place you can run ``frameworkpython `` to get an interactive
124- framework build within the virtualenv. To run a script you can do
125- ``frameworkpython test.py `` where ``test.py `` is a script that requires a
126- framework build. To run an interactive ``IPython `` session with the framework
127- build within the virtual environment you can do ``frameworkpython -m IPython ``
128-
129- ``PYTHONHOME `` Function
130- ^^^^^^^^^^^^^^^^^^^^^^^
131-
132- Alternatively you can define a function in your ``.bashrc `` using
133-
134- .. code :: bash
135-
136- function frameworkpython {
137- if [[ ! -z " $VIRTUAL_ENV " ]]; then
138- PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python " $@ "
139- else
140- /usr/local/bin/python " $@ "
141- fi
142- }
143-
144- This function can then be used in all of your virtualenvs without having to
145- fix every single one of them.
146-
147- PythonW Compiler
148- ^^^^^^^^^^^^^^^^
149-
150- In addition
151- `virtualenv-pythonw-osx <https://github.com/gldnspud/virtualenv-pythonw-osx >`_
152- provides an alternative workaround which may be used to solve the issue.
0 commit comments