Skip to content
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

cannot install pyTsetlinMachine on windows10? #7

Open
SeekPoint opened this issue Feb 10, 2021 · 3 comments
Open

cannot install pyTsetlinMachine on windows10? #7

SeekPoint opened this issue Feb 10, 2021 · 3 comments

Comments

@SeekPoint
Copy link

No description provided.

@andife
Copy link

andife commented Feb 10, 2021

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.

@broersma
Copy link

broersma commented Mar 12, 2021

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

@schuderer
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants