pyTsetlinMachine
pyTsetlinMachine copied to clipboard
cannot install pyTsetlinMachine on windows10?
Hello, I also tried this first. At the end I'll use "Windows Subsystem for Linux 2 (WSL2) and Visual Studio Code on Windows10. I installed pyTsetlinMachine in WSL2 and access to it by using https://code.visualstudio.com/blogs/2019/09/03/wsl2. Maybe that would also work for you.
I had to perform the following steps on Windows 10 to be able to run pip install ../pyTsetlinMachine/ (where ../pyTsetlinMachine/ is the path to my local Git checkout of pyTsetlinMachine):
- Install and download Visual Studio 2019 (Community edition is fine) and Build Tools for Visual Studio 2019: https://visualstudio.microsoft.com/downloads/
- Remove
#include <sys/time.h>fromIndexedTsetlinMachine.c(it's *nix-specific AFAIUI, but the include seems to be dead code for this project). - Create a file called
libTM.cin thepyTsetlinMachinefolder, containingvoid* PyInit_libTM() { return 0; }to fool setuptools into thinking this is a bona-fide Python extension. 😬 (See also https://stackoverflow.com/questions/49299905/error-lnk2001-unresolved-external-symbol-pyinit and https://docs.python.org/3/extending/extending.html) - Add the path to
libTM.ctoExtension-constructor call insetup.pyon line 3, so line 4 becomes:sources = ['pyTsetlinMachine/ConvolutionalTsetlinMachine.c', 'pyTsetlinMachine/EmbeddingTsetlinMachine.c', 'pyTsetlinMachine/MultiClassConvolutionalTsetlinMachine.c', 'pyTsetlinMachine/Tools.c', 'pyTsetlinMachine/IndexedTsetlinMachine.c', 'pyTsetlinMachine/libTM.c'], - Add a list of symbols that need to be exported as an additional
export_symbolsparameter of theExtension-constructor call on line 3 insetup.py, see also https://docs.python.org/3/distutils/setupscript.html#other-options (adding__declspec( dllexport )everywhere in the C sources would also work, but this seems a little cleaner):export_symbols=[ 'CreateEmbeddingTsetlinMachine', 'etm_destroy', 'etm_fit', 'etm_initialize', 'etm_predict', 'etm_ta_state', 'etm_ta_action', 'etm_set_state', 'etm_get_state', 'etm_transform', 'etm_clause_configuration', 'etm_clause_sharing', 'CreateMultiClassTsetlinMachine', 'mc_tm_destroy', 'mc_tm_fit', 'mc_tm_initialize', 'mc_tm_predict', 'mc_tm_ta_state', 'mc_tm_ta_action', 'mc_tm_set_state', 'mc_tm_get_state', 'mc_tm_transform', 'mc_tm_clause_configuration', 'CreateTsetlinMachine', 'tm_fit_regression', 'tm_predict_regression', 'tm_encode', 'CreateIndexedTsetlinMachine', 'itm_destroy', 'itm_initialize', 'itm_predict', 'itm_fit', 'itm_transform'] - Run
pip install ../pyTsetlinMachine/and it should compile and install and make pyTsetlinMachine available in your Python environment.
(A little more background: AFAIUI, it seems setuptools on Windows is a little more picky about what you call a Python extension. On other platforms this project's setup.py basically asks setuptools to just build a regular dynamic library for us, which is then dynamically loaded by some numpy functionality in tm.py. An actual Python extension would have an implementation of the PyInit method which returns a PyObject * which exposes the relevant functions.)
Thank you @broersma for providing these steps! In order to get the RegressionTsetlinMachine demo to run, I had to add a few more symbols to the export_symbols line of setyp.py (specifically, the symbols tm_get_state, tm_set_state and tm_destroy - conveniently, the AttributeErrors tell you exactly which symbol names to add to the list). This line now looks like this:
export_symbols=[ 'CreateEmbeddingTsetlinMachine', 'etm_destroy', 'etm_fit', 'etm_initialize', 'etm_predict', 'etm_ta_state', 'etm_ta_action', 'etm_set_state', 'etm_get_state', 'etm_transform', 'etm_clause_configuration', 'etm_clause_sharing', 'CreateMultiClassTsetlinMachine', 'mc_tm_destroy', 'mc_tm_fit', 'mc_tm_initialize', 'mc_tm_predict', 'mc_tm_ta_state', 'mc_tm_ta_action', 'mc_tm_set_state', 'mc_tm_get_state', 'mc_tm_transform', 'mc_tm_clause_configuration', 'CreateTsetlinMachine', 'tm_fit_regression', 'tm_predict_regression', 'tm_encode', 'tm_set_state', 'tm_get_state', 'tm_destroy', 'CreateIndexedTsetlinMachine', 'itm_destroy', 'itm_initialize', 'itm_predict', 'itm_fit', 'itm_transform' ],