pyTsetlinMachine icon indicating copy to clipboard operation
pyTsetlinMachine copied to clipboard

cannot install pyTsetlinMachine on windows10?

Open SeekPoint opened this issue 3 years ago • 3 comments

SeekPoint avatar Feb 10 '21 02:02 SeekPoint

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.

andife avatar Feb 10 '21 06:02 andife

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):

  1. Install and download Visual Studio 2019 (Community edition is fine) and Build Tools for Visual Studio 2019: https://visualstudio.microsoft.com/downloads/
  2. Remove #include <sys/time.h> from IndexedTsetlinMachine.c (it's *nix-specific AFAIUI, but the include seems to be dead code for this project).
  3. Create a file called libTM.c in the pyTsetlinMachine folder, containing void* 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)
  4. Add the path to libTM.c to Extension-constructor call in setup.py on 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'],
  5. Add a list of symbols that need to be exported as an additional export_symbols parameter of the Extension-constructor call on line 3 in setup.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']
  6. 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.)

broersma avatar Mar 12 '21 09:03 broersma

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' ],

schuderer avatar Jul 01 '22 09:07 schuderer