1

My Situation

I've installed Microsoft Z3 (Z3 [version 4.3.0 - 64 bit]. (C) 2006) and it's pyc binaries for Python2.

I've written an Python3 package which needs access to z3 functionality.

In order to be able to use the pyc binaries with my Python3 package, I decompyle the z3 binaries and applied 2to3.

My Problem

Int('string') doesn't work because Z3Py isn't able to handle the new <class 'str'> used as 'string' argument:

>>> import z3; z3.Int('abc')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".\bin\z3.py", line 2931, in Int
    return ArithRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), IntSort(ctx).ast), ctx)
  File ".\bin\z3.py", line 72, in to_symbol
    return Z3_mk_string_symbol(_get_ctx(ctx).ref(), s)
  File ".\bin\z3core.py", line 1430, in Z3_mk_string_symbol
    r = lib().Z3_mk_string_symbol(a0, a1)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type

My Questions

  • It's a little bit hacky to need to decompyle Z3's *.pyc files first. So, are there any Z3Py source codes available?
  • Is there already an existing Z3Py port to Python3?
  • Any other idea how to get Z3Py to run with Python3?

Thanks. - If anything's unclear, please leave a question comment.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
fdj815
  • 569
  • 1
  • 7
  • 15

1 Answers1

2

The unstable (work-in-progress) has support for Python 3. This feature will be available in the next Z3 release (v4.3.2). In the meantime, you can build the unstable branch using the instructions found here.

Leonardo de Moura
  • 21,065
  • 2
  • 47
  • 53
  • Thanks for your answer - But it seems like it **doesn't work together with the library** correctly. When calling a Python method of `z3`: `File ".\build\z3core.py", line 24, in lib raise Z3Exception("init(Z3_LIBRARY_PATH) must be invoked before using Z3-python")` - Any idea? – fdj815 Mar 25 '13 at 08:53
  • 2
    This is error is usually generated when the Z3 shared object (*.so Linux, *.dylib OSX, or *.dll Windows) can't be found. You should include the shared object in you search path: on Linux you have to set the LD_LIBRARY_PATH environment variable. Another option is to invoke `init` with the full path to the Z3 shared object. Which platform are you using? – Leonardo de Moura Mar 25 '13 at 15:21
  • This project is thought to run on a Windows 7 environment. My object is currently located at `.\build\libz3.dll`. **Is there a special environment var I have** to set on Windows or is there anything else I can do to get Z3Py to find the object? – fdj815 Mar 25 '13 at 19:29
  • You should include the path to libz3.dll in the `PATH` environment variable. – Leonardo de Moura Mar 25 '13 at 21:24
  • The path to `.\build` is actually included in `$PATH`. Any other reason why that exception could occur? – fdj815 Mar 25 '13 at 23:06
  • `.\build` is a relative path. Are you including the actual path in `PATH`. Have you tried to invoke `init('dir\libz3.dll')` in your python script? Another potential problem, if you are using a 32 bit python.exe, you must use a 32 bit DLL, even if you are using in 64 bit machine. – Leonardo de Moura Mar 25 '13 at 23:12
  • **(1)** I'm using the absolute path `C:\[PathTo]\build` in `$PATH` – **(2)** `z3.init(libpath)` throws `File ".\Python\3.3\lib\ctypes\__init__.py", line 353, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specific module could not be found`. – **(3)** I'm using `Python 3.3.0 [MSC v.1600 64 bit (AMD64)] on win32` together with the `libz3.dll` built by `nmake`. – Thanks, hoping this piece of information makes sense to you. – fdj815 Mar 25 '13 at 23:23
  • I guess the `libz3.dll` is probably a 32 bit DLL. Could you try to compile the `libz3.dll` again using the (64-bit) instructions found here: http://z3.codeplex.com/wikipage?title=Z3Py%20on%20Windows&referringTitle=Documentation – Leonardo de Moura Mar 25 '13 at 23:33
  • 1
    Another option is to use the precompiled DLL in the nightly builds for Windows 64-bit. This link has additional information: http://research.microsoft.com/en-us/um/people/leonardo/blog/2013/02/15/precompiled.html – Leonardo de Moura Mar 25 '13 at 23:35
  • Thanks - Now I'm using my self-compiled `unstable` build with the `libz3.dll` file replaced by the one from the `nightly` channel and I didn't encounter any problems so far. – fdj815 Mar 25 '13 at 23:50