Created
September 10, 2018 09:36
-
-
Save TobeyQin/c3d942c9b0cf5db0a7eb5221c2a14248 to your computer and use it in GitHub Desktop.
build caffe2 wheel package for python3 on windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Build Caffe2 CPU version on windows platform with python3: | |
1. Pip install prerequisites packages | |
2. Download protobuffer3.1(.exe file) from website | |
3. Add code in caffe2\caffe2\python\pybind_state.cc to build correctly for Python3.5: | |
#if PY_MAJOR_VERSION >= 3 | |
#ifndef PyString_AsString | |
#define PyString_AsString PyUnicode_AsUTF8 | |
#endif | |
#ifndef PyString_Check | |
#define PyString_Check PyUnicode_Check | |
#endif | |
#endif | |
4. Build lmdb package: | |
Can NOT use Nuget package. | |
Need to download lmdb files (lmdb.h mdb.c midl.h midl.c) from github, and build as static library(/MT). | |
5. Make "build_XX" directory under caffe2 directory | |
6. In" build_XX" directory, run: | |
a. Set LMDB_DIR (the lmdb library is built to static library(/MT) [not dynamic library]): | |
<directory of LMDB library> | |
set LMDB_DIR=D:\src\packages\lmdb.v140.0.9.17\Release | |
b. Run Cmake: | |
cmake ../ -G"Visual Studio 14 2015 Win64" -DCMAKE_VERBOSE_MAKEFILE=1 -DBUILD_SHARED_LIBS=OFF -DBUILD_TEST=OFF -DCMAKE_BUILD_TYPE=Release -DUSE_CUDA=OFF -DPROTOBUF_PROTOC_EXECUTABLE=D:\src\protoc-3.1.0-win32\bin\protoc.exe -DCMAKE_CXX_FLAGS=/MP || exit /b | |
cmake --build . --config Release || exit /b | |
[NOTE] | |
1) If you want to use cuda, you must build with -G"Visual Studio 14 2015 Win64" | |
2) If you just use CPU only, you can build with -G"Visual Studio 15 2017 Win64" | |
7. Write setup.py, MANIFEST.in, README.rst [optional: requirements.txt, test-requirements.txt] | |
8. Create wheel, run: | |
python setup.py bdist_wheel --universal | |
9. If you want to specified python version: add this when run cmake command (the example is run in LINUX): | |
-DPYTHON_EXECUTABLE=/usr/bin/python3.5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment