【问题标题】:Using Z3Py With Python 3.3在 Python 3.3 中使用 Z3Py
【发布时间】:2013-03-24 12:51:11
【问题描述】:

我的情况

我已经安装了 Microsoft Z3 (Z3 [version 4.3.0 - 64 bit]. (C) 2006),它是 Python2 的 pyc 二进制文件。

我编写了一个 Python3 包,它需要访问 z3 功能。

为了能够将pyc 二进制文件与我的Python3 包一起使用,我decompyle z3 二进制文件并应用了2to3

我的问题

Int('string') 不起作用,因为 Z3Py 无法处理用作 'string' 参数的新 <class 'str'>

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

我的问题

  • 首先需要decompyle Z3 的*.pyc 文件有点麻烦。那么,有没有可用的 Z3Py 源代码?
  • 是否已有到 Python3 的 Z3Py 端口?
  • 还有其他想法如何让 Z3Py 与 Python3 一起运行

谢谢。 - 如果有任何不清楚的地方,请留下问题评论。

【问题讨论】:

  • Z3 不是开源的吗? z3.codeplex.com
  • @Kabie 基本上是的,但是在那个存储库中没有任何 Python3 兼容版本的源代码。

标签: python python-3.x z3 python-2to3


【解决方案1】:

unstable (work-in-progress) 支持 Python 3。此功能将在下一个 Z3 版本 (v4.3.2) 中提供。同时,您可以使用找到的指令here 构建unstable 分支。

【讨论】:

  • 感谢您的回答 - 但它似乎 不能与库一起使用正确。当调用z3 的 Python 方法时:File ".\build\z3core.py", line 24, in lib raise Z3Exception("init(Z3_LIBRARY_PATH) must be invoked before using Z3-python") - 知道吗?
  • 当找不到 Z3 共享对象(*.so Linux、*.dylib OSX 或 *.dll Windows)时,通常会生成此错误。您应该在搜索路径中包含共享对象:在 Linux 上,您必须设置 LD_LIBRARY_PATH 环境变量。另一种选择是使用 Z3 共享对象的完整路径调用 init。您使用的是哪个平台?
  • 这个项目被认为是在 Windows 7 环境下运行的。我的对象目前位于.\build\libz3.dll我有一个特殊的环境变量要在 Windows 上设置还是我可以做些什么来让 Z3Py 找到对象?
  • 您应该在PATH 环境变量中包含libz3.dll 的路径。
  • 另一种选择是在 Windows 64 位的夜间构建中使用预编译的 DLL。此链接包含更多信息:research.microsoft.com/en-us/um/people/leonardo/blog/2013/02/15/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
相关资源
最近更新 更多