Skip to content

Commit a284aa5

Browse files
author
Benno Evers
committed
Document flag for changing python version, make the mechanism more general
1 parent 4f56678 commit a284aa5

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,22 @@ The C++-part of the library consists of the single header file `matplotlibcpp.h`
103103
anywhere.
104104
Since a python interpreter is opened internally, it is necessary to link against `libpython2.7` in order to use
105105
matplotlib-cpp.
106-
(There should be no problems using python3 instead of python2.7, if desired)
106+
107+
# Python 3
108+
109+
The code is written in a way that should support both python2 and python3.
110+
By default, matplotlib-cpp will try to "just work" and include the header `python2.7/Python.h`.
111+
112+
To modify this behaviour the define `MATPLOTLIBCPP_PYTHON_HEADER`,
113+
can be set to an absolute or relative path:
114+
115+
#define MATPLOTLIBCPP_PYTHON_HEADER /usr/include/python3.6/Python.h
116+
#include "matplotlibcpp.h"
117+
118+
or
119+
120+
g++ -DMATPLOTLIBCPP_PYTHON_HEADER=Python.h -I/usr/include/python3.6 <...>
121+
107122

108123
Why?
109124
----

matplotlibcpp.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#include <functional>
1111
#endif
1212

13-
#ifdef PY_INCLUDE
14-
#include <Python.h>
15-
#else
13+
// i.e. g++ -DMATPLOTLIBCPP_PYTHON_HEADER=/usr/include/python3.6/Python.h [...]
14+
#ifdef MATPLOTLIBCPP_PYTHON_HEADER
15+
#define STRINGIFY_(x) #x
16+
#define STRINGIFY(x) STRINGIFY_(x)
17+
#include STRINGIFY(MATPLOTLIBCPP_PYTHON_HEADER)
18+
#else // This should stay the default for backwards compatibility
1619
#include <python2.7/Python.h>
1720
#endif
1821

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy