Python extensions can be compiled in two ways: using Microsoft Visual Studio with a version matching that of your python (see here, and here), or using MinGW, which is a mini-linux environment to cross-compile for windows, but using all the linux compiling toolchain. Since Python 3.5, the recommended way is using Visual Studio, as Microsoft introduced changes in the compiler that are not 100% compatible with MINGW, actually it is recommended not to use mingw (see this and this). However, librdata (the library that pyreadr wraps) is written in a way that depends on Posix (unix) libraries, and therefore cannot be compiled with Visual Studio, therefore, one must compile with MINGW.
Initially I compiled using MVSC with the modified file from Jamovi. This however did not work well when trying to compile to use bzip2. Now I am using m2w64-toolchain which is a conda package that makes the process much easier (sources can be taken from librdata as is) and is compatible with Appveyor.
pre-requisite:
- Install Anaconda or Miniconda and prepare the environment: run these commands on the Anaconda prompt and/or activate the conda environment properly
conda install setuptools pandas wheel pip libpython cython
conda install -c msys2 m2w64-toolchain
- compilation:
# set mingw32 as compiler
python setup.py config --compiler=mingw32
# Create a wheel.
python setup.py bdist_wheel
# install the wheel
pip install --pre --no-index --find-links dist/ pyreadr
# run tests (optional)
python.exe tests\test_basic.py