Skip to content

Build support with dependencies for Windows #3388

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
*.py[ocd]
*.so

# Compiled Dependencies #
#########################
windeps/freetype-2.4.11/
windeps/libpng-1.6.7-build/
windeps/libpng-1.6.7/
windeps/zlib-1.2.8/
windeps/tcl8.5.13/
windeps/tk8.5.13/
windeps/msvcr90-x32/
windeps/msvcr90-x64/
windeps/msvcr100-x32/
windeps/msvcr100-x64/
windeps/build_*.cmd

# Python files #
################
# setup.py working directory
Expand Down
47 changes: 35 additions & 12 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ e.g., if the header to some required library is in
Build requirements
==================

These are external packages which you will need to install before
installing matplotlib. If you are building on OSX, see
:ref:`build_osx`. If you are installing dependencies with a package
manager on Linux, you may need to install the development packages
(look for a "-dev" postfix) in addition to the libraries themselves.
These are external packages which you will need to install before installing
matplotlib. If you are building on OSX, see :ref:`build_osx`. If you are
building on Windows, see :ref:`build_windows`. If you are installing
dependencies with a package manager on Linux, you may need to install the
development packages (look for a "-dev" postfix) in addition to the libraries
themselves.

.. note::

Expand Down Expand Up @@ -261,11 +262,11 @@ six 1.3 or later
:term:`dateutil`.

libpng 1.2 (or later)
library for loading and saving :term:`PNG` files (`download
<http://www.libpng.org/pub/png/libpng.html>`__). libpng requires
zlib. If you are a Windows user, you can ignore this because we
build support into the matplotlib single-click installer

library for loading and saving :term:`PNG` files
(`download <http://www.libpng.org/pub/png/libpng.html>`__). libpng
requires zlib. If you are a Windows user, you can ignore this since
the sources are shipped and built as part of the matplotlib build
scripts.

**Optional GUI frameworks**

Expand Down Expand Up @@ -306,8 +307,8 @@ ImageMagick

:term:`freetype` 1.4 (or later)
library for reading true type font files. If you are a windows
user, you can ignore this since we build support into the
matplotlib single click installer.
user, you can ignore this since the sources are shipped and built as part
of the matplotlib build scripts.

**Required libraries that ship with matplotlib**

Expand Down Expand Up @@ -337,3 +338,25 @@ can get the libpng and freetype requirements (darwinports, fink,
the different OSX version (e.g., 10.4 and 10.5). We recommend that you build
the way we do for the OSX release: get the source from the tarball or the
git repository and follow the instruction in :file:`README.osx`.

.. _build_windows:

Building on Windows
======================

The Python shipped from http://www.python.org is compiled with Visual Studio
2008 for versions before 3.3 and Visual Studio 2010 for 3.3 and later.
Python extensions are recommended to be compiled with the same compiler. The
matplotlib `setup.py` looks for the correct version via distutils. The .NET
Framework 4.0 is required for MSBuild, but you likely already have it.

In addition to Visual Studio, `CMake <http://www.cmake.org>`_ is required for
building libpng. For building documentation, you will need to install numpydoc
and miktex. The required freetype, zlib, libpng, tcl, & tk source code is
bundled with matplotlib since there is no canonical Windows package manager.

Instructions as above will build and install in the Python installation used to
launch `setup.py`. Alternatively to build an installation binary that can be
used on other Windows machines with a matching Python, run::

python setup.py bdist_wininst
2 changes: 2 additions & 0 deletions doc/faq/installing_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ line script to the appropriate places.
.. note::
Mac OSX users please see the :ref:`build_osx` guide.

Windows users please see the :ref:`build_windows` guide.

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

> git pull
Expand Down
10 changes: 10 additions & 0 deletions doc/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ def all():
]

for link, target in required_symlinks:
if os.path.isfile(link):
# This is special processing that applies on platforms that don't deal
# with git symlinks -- probably only MS windows.
delete = False
with open(link, 'r') as content:
delete = target == content.read()
if delete:
os.unlink(link)
else:
raise RuntimeError("doc/{} should be a directory or symlink -- it isn't")
if not os.path.exists(link):
if hasattr(os, 'symlink'):
os.symlink(target, link)
Expand Down
38 changes: 33 additions & 5 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sys
import warnings
from textwrap import fill
import setupwin


PY3 = (sys.version_info[0] >= 3)
Expand Down Expand Up @@ -588,6 +589,11 @@ def get_package_data(self):
'style/stylelib/*.mplstyle',
]}

def add_flags(self, ext):
if sys.platform == 'win32':
ext.include_dirs.append(setupwin.config_dir())
ext.lib_dirs.append(setupwin.config_dir())


class SampleData(OptionalPackage):
"""
Expand Down Expand Up @@ -927,7 +933,7 @@ class FreeType(SetupPackage):

def check(self):
if sys.platform == 'win32':
return "Unknown version"
return "building local version {}".format(setupwin.FREETYPE_VERSION)

status, output = getstatusoutput("freetype-config --ftversion")
if status == 0:
Expand Down Expand Up @@ -967,19 +973,27 @@ def version_from_header(self):
return '.'.join([major, minor, patch])

def add_flags(self, ext):
extra_include_dirs = []
extra_library_dirs = []
if sys.platform == 'win32':
extra_include_dirs = [setupwin.config_dir()]
extra_library_dirs = [setupwin.config_dir()]

pkg_config.setup_extension(
ext, 'freetype2',
default_include_dirs=[
'freetype2', 'lib/freetype2/include',
'lib/freetype2/include/freetype2'],
'lib/freetype2/include/freetype2'] + extra_include_dirs,
default_library_dirs=[
'freetype2/lib'],
'freetype2/lib'] + extra_library_dirs,
default_libraries=['freetype', 'z'],
alt_exec='freetype-config')

def get_extension(self):
if sys.platform == 'win32':
setupwin.build_freetype()
return None

ext = make_extension('freetype2', [])
self.add_flags(ext)
return ext
Expand Down Expand Up @@ -1012,12 +1026,22 @@ def check(self):
return str(e) + ' Using unknown version.'

def get_extension(self):
library_dirs = []
include_dirs = []
if sys.platform == 'win32':
setupwin.build_zlib()
setupwin.build_libpng()
library_dirs = [setupwin.config_dir()]
include_dirs = [setupwin.config_dir()]

sources = [
'src/_png.cpp', 'src/mplutils.cpp'
]
ext = make_extension('matplotlib._png', sources)
pkg_config.setup_extension(
ext, 'libpng', default_libraries=['png', 'z'])
ext, 'libpng', default_libraries=['png', 'z'],
default_include_dirs=include_dirs,
default_library_dirs=library_dirs)
Numpy().add_flags(ext)
CXX().add_flags(ext)
return ext
Expand Down Expand Up @@ -1317,6 +1341,9 @@ def check_requirements(self):
return "version %s" % tk_v

def get_extension(self):
if sys.platform == 'win32':
setupwin.build_tcl()

sources = [
'src/agg_py_transforms.cpp',
'src/_tkagg.cpp'
Expand Down Expand Up @@ -1484,14 +1511,15 @@ def hardcoded_tcl_config(self):

def add_flags(self, ext):
if sys.platform == 'win32':
ext.include_dirs.extend([setupwin.tcl_config_dir()])
major, minor1, minor2, s, tmp = sys.version_info
if sys.version_info[0:2] < (3, 4):
ext.include_dirs.extend(['win32_static/include/tcl85'])
ext.libraries.extend(['tk85', 'tcl85'])
else:
ext.include_dirs.extend(['win32_static/include/tcl86'])
ext.libraries.extend(['tk86t', 'tcl86t'])
ext.library_dirs.extend([os.path.join(sys.prefix, 'dlls')])
ext.library_dirs.extend([os.path.join(sys.prefix, 'tcl')])

elif sys.platform == 'darwin':
# this config section lifted directly from Imaging - thanks to
Expand Down
Loading