Skip to content

Update Windows Scripts & Add Python 3 support for numpy init #42

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 1 commit 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
5 changes: 4 additions & 1 deletion contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(${PYTHONHOME}/include)
include_directories(${PYTHONHOME}/Lib/site-packages/numpy/core/include)
link_directories(${PYTHONHOME}/libs)

add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h)
# add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h)
# add_definitions(-DWITHOUT_NUMPY)

# message(STATUS "*** dump start cmake variables ***")
# get_cmake_property(_variableNames VARIABLES)
Expand All @@ -19,3 +21,4 @@ add_definitions(-DMATPLOTLIBCPP_PYTHON_HEADER=Python.h)
add_executable(minimal ${CMAKE_CURRENT_SOURCE_DIR}/../examples/minimal.cpp)
add_executable(basic ${CMAKE_CURRENT_SOURCE_DIR}/../examples/basic.cpp)
add_executable(modern ${CMAKE_CURRENT_SOURCE_DIR}/../examples/modern.cpp)
add_executable(animation ${CMAKE_CURRENT_SOURCE_DIR}/../examples/animation.cpp)
19 changes: 18 additions & 1 deletion contrib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,29 @@ contributors are not required to and may be unable to check whether their
changes break any of them.

## Windows support
Tested on the following environment
* Windows 10 - 64bit
* Anaconda 4.3 (64 bit)
* Python 3.6.0
* CMake 3.9.4
* Visual Studio 2017, 2015, 2013

### Visual Studio 2017
Set Environment Variable VS150COMNTOOLS to [yourInstallPath]\Common7\Tools
e.g. C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\

### Configuring and Building Samples
1. Edit WinBuild.cmd for your environment(Line:4-6)
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=[Your Visual Studio Version(12, 14, 15)]
if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
if NOT DEFINED PYTHONHOME set PYTHONHOME=[Your Python Path]

2. Run WinBuild.cmd to build
```cmd
> cd contrib
> WinBuild.cmd
```

The `WinBuild.cmd` will set up temporal ENV variables and build binaries in (matplotlib root)/examples with the Release configuration.

3. Find exe files in examples/build/Release
Note: platforms folder is important to make qt works.
16 changes: 12 additions & 4 deletions contrib/WinBuild.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
@setlocal EnableDelayedExpansion

if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
if NOT DEFINED MSVC_VERSION set MSVC_VERSION=15
if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
if NOT DEFINED PYTHONHOME set PYTHONHOME=C:/Users/%username%/Anaconda3

Expand All @@ -14,13 +14,21 @@ if "%MSVC_VERSION%"=="14" (
) else if "%MSVC_VERSION%"=="12" (
if "%processor_architecture%" == "AMD64" (
set CMAKE_GENERATOR=Visual Studio 12 2013 Win64

) else (
set CMAKE_GENERATOR=Visual Studio 12 2013
)
) else if "%MSVC_VERSION%"=="15" (
if "%processor_architecture%" == "AMD64" (
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
) else (
set CMAKE_GENERATOR=Visual Studio 15 2017
)
)
if "%MSVC_VERSION%"=="15" (
set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\Auxiliary\Build\vcvarsall.bat
) else (
set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat
)

set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat
call "%batch_file%" %processor_architecture%

pushd ..
Expand Down
10 changes: 9 additions & 1 deletion matplotlibcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ namespace matplotlibcpp {
}

private:
#if PY_MAJOR_VERSION >= 3
int init_numpy(){
#else
void init_numpy(){
#endif
import_array()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the late review! The rest of the PR looks great, but I think this is missing a return 0; in the Python 3 case. It would be great if you could amend and force push this.

}

_interpreter() {

// optional but recommended
Expand All @@ -80,7 +88,7 @@ namespace matplotlibcpp {
Py_Initialize();

#ifndef WITHOUT_NUMPY
import_array(); // initialize numpy C-API
init_numpy(); // initialize numpy C-API
#endif

PyObject* matplotlibname = PyString_FromString("matplotlib");
Expand Down