1

I learned that there is a version of PyCLIPS based on CLIPS version 6.30. The same (or similar) PyCLIPS version can also be installed via pip, see here.

On Linux, both approaches work fine, i.e. installing via git clone + setup.py, or via pip. On Windows, it worked only with cygwin 64bit. pip install pyclips failed (I suppose due to the missing '-DWIN_MVC' flag, see step 7 below).

However, I would like to have a PyCLIPS based on CLIPS 6.30 on a 'regular' Windows python, to be precise Python2.7 32 bit on a Windows 7 64 bit. I have visual studio express 2008 installed.

What I tried:

  1. git clone https://github.com/almostearthling/pyclips.git
  2. cd pyclips
  3. git checkout pyclips-1.1_clips-6.30
  4. delete the file clipssrc
  5. download the CLIPS 6.30 source code from the official repository
  6. create a new folder a newly created folder clipssrc inside the pyclips folder
  7. extract the contents of the core folder into the clipssrc folder
  8. insetup.py at around line 738, add '-DWIN_MVC' to the CFLAGS list
  9. install patch utility for windows and add it to PATH
  10. start visual studio express 2008 (32 bit) command prompt
  11. cd into the pyclips folder
  12. run python setup.py build
  13. If the built went through (it should) install via python setup.py install

Although the built and installation went through, large integers still cause an error, as they did in CLIPS before version 6.30. This means CLIPS is not able to cope with integers that are larger than 2147483648 (sys.maxint+1 on python 2.7 32 bit).

During compilation with visual studio 2008 I got the Warning "conversion from '__int64' to 'long', possible loss of data". I changed the types of the corresponding variables to long long. The Warnings disappeared but the error with large integers still exists.

How do I install PyCLIPS based on CLIPS 6.30 on Windows 7 64 bit for use with a 32bit Windows Python 2.7 ?

EDIT 1: I tried to install it with cygwin 32 bit - and it did not work. So maybe it is a 32/64 bit issue? The 32bit Version of clips (installed via the official installer) works fine on my Windows 7 64 bit...

EDIT 2: It seems to work with python interpreters that have a sys.maxint of 9223372036854775807 but not with interpreters that have a sys.maxint of 2147483647. Interestingly, even the 64bit Windows Python has the latter value.

Summary:

  • cygwin Python 64 bit, maxint: 9223372036854775807, no error
  • cygwin Python 32 bit, maxint: 2147483647, error
  • Windows Python 2.7 32 bit, maxint: 2147483647, error
  • Windows Python 2.7 64 bit, maxint: 2147483647, error
langlauf.io
  • 3,009
  • 2
  • 28
  • 45
  • Perhaps the issue is with the Py_BuildValue calls in clipsmodule.c for converting from C integers to python integers. Maybe calls like Py_BuildValue("(il)", t, DOPToLong(o)) need to be Py_BuildValue("(iL)", t, DOPToLong(o)) based on https://docs.python.org/2/c-api/arg.html. – Gary Riley Dec 31 '16 at 20:48
  • In file clipsmodule.c I changed line 1493 to `p = Py_BuildValue("(iL)", t, ValueToLong(GetMFValue(ptr, pos)));` and line 1582 to `p = Py_BuildValue("(iL)", t, DOPToLong(o));` but unfortunately this did not help (yet). Any other ideas? – langlauf.io Jan 01 '17 at 13:04
  • My suspicion is that conversion is failing either when passing the value between CLIPS and Python or that the value is being stored on the Python side as an int when it should be a long. I have very little experience with Python so I'm not familiar with the interface for passing values between C and Python, but I would suggest putting some code in the clipsmodule.c and clips_wrap.py to try to determine the point at which the conversion fails. – Gary Riley Jan 02 '17 at 18:10
  • Sou are right I think. Today I did exactly that and I may found the right spot. I changed some lines and now it seems to not throw errors on large integers any more. I need to verify though if I did not break anything. I will post any reliable results on the pyclips github repo. – langlauf.io Jan 02 '17 at 18:15
  • @GaryRiley I think I fixed it. See here: https://github.com/almostearthling/pyclips/issues/2 – langlauf.io Jan 05 '17 at 15:08
  • Nice. So it was a combination of changing some of the Py_BuildValue signatures and using PyLong_AsLongLong in clipsmodule.c? – Gary Riley Jan 05 '17 at 17:15
  • And setting a c variable to long long, "i" if I remember correctly. – langlauf.io Jan 05 '17 at 17:40
  • @GaryRiley I submitted a pull request to the official pyclips repo on github. There you can see all changes. Thanks for your help. – langlauf.io Jan 07 '17 at 18:57

0 Answers0