Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 334ee5d

Browse files
committed
Update build docs.
TL;DR: set MPLLOCALFREETYPE=1 and call it a day, unless you really know what you want to do.
1 parent 6a31fed commit 334ee5d

File tree

3 files changed

+61
-115
lines changed

3 files changed

+61
-115
lines changed

INSTALL.rst

Lines changed: 52 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ toolchain is prefixed. This may be used for cross compiling. ::
9898
export CXX=x86_64-pc-linux-gnu-g++
9999
export PKG_CONFIG=x86_64-pc-linux-gnu-pkg-config
100100

101-
Once you have satisfied the requirements detailed below (mainly
102-
Python, NumPy, and FreeType), you can build Matplotlib.
101+
Once you have satisfied the requirements detailed below (i.e., Python and
102+
FreeType), you can build Matplotlib.
103103
::
104104

105105
cd matplotlib
@@ -165,96 +165,78 @@ etc., you can install the following:
165165
* `LaTeX <https://miktex.org/>`_ and `GhostScript (>=9.0)
166166
<https://ghostscript.com/download/>`_ : for rendering text with LaTeX.
167167

168-
.. note::
169-
170-
Matplotlib depends on non-Python libraries.
168+
FreeType
169+
--------
171170

172-
On Linux and OSX, pkg-config_ can be used to find required non-Python
173-
libraries and thus make the install go more smoothly if the libraries and
174-
headers are not in the expected locations.
171+
Matplotlib depends on FreeType, a font rendering library. It can either
172+
download and build its own copy of the library, or use a copy of FreeType
173+
already installed in your system.
175174

176-
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
175+
The easiest option is to make Matplotlib download and build FreeType. This is
176+
done by setting the :envvar:`MPLLOCALFREETYPE` environment variable to 1 -- on
177+
Linux and OSX:
177178

178-
If not using pkg-config (in particular on Windows), you may need to set
179-
the include path (to the FreeType headers) and link path (to the FreeType
180-
library) explicitly, if they are not in standard locations. This can be
181-
done using standard environment variables -- on Linux and OSX:
179+
.. code-block:: sh
182180
183-
.. code-block:: sh
181+
export MPLLOCALFREETYPE=1
184182
185-
export CFLAGS='-I/directory/containing/ft2build.h'
186-
export LDFLAGS='-L/directory/containing/libfreetype.so'
183+
and on Windows:
187184

188-
and on Windows:
185+
.. code-block:: bat
189186
190-
.. code-block:: bat
187+
set MPLLOCALFREETYPE=1
191188
192-
set CL=/IC:\directory\containing\ft2build.h
193-
set LINK=/LIBPATH:C:\directory\containing\freetype.lib
194-
195-
.. note::
189+
and you can continue the installation (``python -m pip install .``), ignoring
190+
everything that follows.
196191

197-
The following libraries are shipped with Matplotlib:
192+
If you wish, instead, to use the system FreeType, you need to install the
193+
FreeType library and headers. This can be achieved using a package manager:
198194

199-
- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
200-
- ``qhull``: to compute Delaunay triangulation;
201-
- ``ttconv``: a TrueType font utility.
195+
.. code-block:: sh
202196
203-
.. _build_linux:
197+
# Pick ONE of the following:
198+
sudo apt install libfreetype6-dev # Debian/Ubuntu
199+
sudo dnf install freetype-devel # Fedora
200+
brew install freetype # macOS with Homebrew
201+
conda install freetype # conda, any OS
204202
205-
Building on Linux
206-
-----------------
203+
On Linux and macOS, it is also recommended to install pkg-config_, a helper
204+
tool for locating FreeType:
207205

208-
It is easiest to use your system package manager to install the dependencies.
206+
.. code-block:: sh
209207
210-
If you are on Debian/Ubuntu, you can get all the dependencies
211-
required to build Matplotlib with::
208+
# Pick ONE of the following:
209+
sudo apt install pkg-config # Debian/Ubuntu
210+
sudo dnf install pkgconf # Fedora
211+
brew install pkg-config # macOS with Homebrew
212+
conda install pkg-config # conda
212213
213-
sudo apt-get build-dep python-matplotlib
214+
.. _pkg-config: https://www.freedesktop.org/wiki/Software/pkg-config/
214215

215-
If you are on Fedora, you can get all the dependencies required to build
216-
Matplotlib with::
216+
If not using pkg-config (in particular on Windows), you may need to set the
217+
include path (to the FreeType headers) and link path (to the FreeType library)
218+
explicitly, if they are not in standard locations. This can be done using
219+
standard environment variables -- on Linux and OSX:
217220

218-
sudo dnf builddep python-matplotlib
221+
.. code-block:: sh
219222
220-
If you are on RedHat, you can get all the dependencies required to build
221-
Matplotlib by first installing ``yum-builddep`` and then running::
223+
export CFLAGS='-I/directory/containing/ft2build.h'
224+
export LDFLAGS='-L/directory/containing/libfreetype.so'
222225
223-
su -c "yum-builddep python-matplotlib"
226+
and on Windows:
224227

225-
These commands do not build Matplotlib, but instead get and install the
226-
build dependencies, which will make building from source easier.
228+
.. code-block:: bat
227229
228-
.. _build_osx:
230+
set CL=/IC:\directory\containing\ft2build.h
231+
set LINK=/LIBPATH:C:\directory\containing\freetype.lib
229232
230-
Building on macOS
231-
-----------------
232-
233-
The build situation on macOS is complicated by the various places one
234-
can get FreeType (MacPorts, Fink,
235-
/usr/X11R6), the different architectures (e.g., x86, ppc, universal), and
236-
the different macOS versions (e.g., 10.4 and 10.5). We recommend that you build
237-
the way we do for the macOS release: get the source from the tarball or the
238-
git repository and install the required dependencies through a third-party
239-
package manager. Two widely used package managers are Homebrew, and MacPorts.
240-
The following example illustrates how to install FreeType using
241-
``brew``::
242-
243-
brew install freetype pkg-config
244-
245-
If you are using MacPorts, execute the following instead::
246-
247-
port install freetype pkgconfig
248-
249-
After installing the above requirements, install Matplotlib from source by
250-
executing::
233+
.. note::
251234

252-
python -m pip install .
235+
The following libraries are shipped with Matplotlib:
253236

254-
Note that your environment is somewhat important. Some conda users have
255-
found that, to run the tests, their PYTHONPATH must include
256-
/path/to/anaconda/.../site-packages and their DYLD_FALLBACK_LIBRARY_PATH
257-
must include /path/to/anaconda/lib.
237+
- ``Agg``: the Anti-Grain Geometry C++ rendering engine;
238+
- ``qhull``: to compute Delaunay triangulation;
239+
- ``ttconv``: a TrueType font utility.
258240

259241
.. _build_windows:
260242

@@ -264,40 +246,14 @@ Building on Windows
264246
The Python shipped from https://www.python.org is compiled with Visual Studio
265247
2015 for 3.5+. Python extensions should be compiled with the same
266248
compiler, see e.g.
267-
https://packaging.python.org/guides/packaging-binary-extensions/#setting-up-a-build-environment-on-windows
249+
https://packaging.python.org/guides/packaging-binary-extensions/#binary-extensions-for-windows
268250
for how to set up a build environment.
269251

270-
Since there is no canonical Windows package manager, the methods for building
271-
FreeType from source code are documented as a build script
272-
at `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_.
273-
274-
There are a few possibilities to build Matplotlib on Windows:
275-
276-
* Wheels via `matplotlib-winbuild <https://github.com/jbmohler/matplotlib-winbuild>`_
277-
* Wheels by using conda packages (see below)
278-
* Conda packages (see below)
279-
280252
If you are building your own Matplotlib wheels (or sdists), note that any DLLs
281253
that you copy into the source tree will be packaged too.
282254

283-
Wheel builds using conda packages
284-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
285-
286-
This is a wheel build, but we use conda packages to get all the requirements.
287-
FreeType is statically linked and therefore not needed during the wheel install.
288-
289-
Set up the conda environment. Note, if you want a qt backend, add ``pyqt`` to
290-
the list of conda packages.
291-
292-
::
293-
294-
conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk freetype
295-
conda activate matplotlib_build
296-
python setup.py bdist_wheel
297-
298-
299255
Conda packages
300-
^^^^^^^^^^^^^^
256+
--------------
301257

302258
The conda packaging scripts for Matplotlib are available at
303259
https://github.com/conda-forge/matplotlib-feedstock.

doc/faq/environment_variables_faq.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ Environment Variables
3131
defined, :file:`{HOME}/.config/matplotlib` is generally used on unix-like
3232
systems and :file:`{HOME}/.matplotlib` is used on other platforms, if they are
3333
writable. Otherwise, the python standard library :func:`tempfile.gettempdir`
34-
is used to find a base directory in which the :file:`matplotlib` subdirectory
34+
is used to find a base directory in which the :file:`matplotlib` subdirectory
3535
is created.
3636

37+
.. envvar:: MPLLOCALFREETYPE
38+
39+
If set, this environment variable directs Matplotlib's build script to
40+
download and build its own copy of the FreeType library.
41+
3742
.. envvar:: PATH
3843

3944
The list of directories searched to find executable programs.

doc/faq/installing_faq.rst

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,13 @@ or::
182182

183183
git clone git://github.com/matplotlib/matplotlib.git
184184

185-
and build and install as usual with::
185+
and build and install with::
186186

187187
cd matplotlib
188+
export MPLLOCALFREETYPE=1 # on Linux and OSX.
189+
set MPLLOCALFREETYPE=1 # on Windows.
188190
python -mpip install .
189191

190-
.. note::
191-
192-
If you are on Debian/Ubuntu, you can get all the dependencies required to
193-
build Matplotlib with::
194-
195-
sudo apt-get build-dep python-matplotlib
196-
197-
If you are on Fedora/RedHat, you can get all the dependencies required to
198-
build Matplotlib by first installing ``yum-builddep`` and then running::
199-
200-
su -c 'yum-builddep python-matplotlib'
201-
202-
This does not build Matplotlib, but it does get all of the build
203-
dependencies, which will make building from source easier.
204-
205192
If you want to be able to follow the development branch as it changes
206193
just replace the last step with::
207194

@@ -211,8 +198,6 @@ This creates links and installs the command line script in the appropriate
211198
places.
212199

213200
.. note::
214-
OSX users please see the :ref:`build_osx` guide.
215-
216201
Windows users please see the :ref:`build_windows` guide.
217202

218203
Then, if you want to update your Matplotlib at any time, just do::

0 commit comments

Comments
 (0)