简体   繁体   English

在本地使用Z3Py

[英]Using Z3Py locally

I'm using Python 2.7.3 on Windows XP via the IDLE GUI, and I'm trying to run Z3 4.0 locally via the Python API. 我正在通过IDLE GUI在Windows XP上使用Python 2.7.3,并且试图通过Python API在本地运行Z3 4.0。

This line works fine: 这行工作正常:

>>> from z3 import *

This line doesn't: 该行不:

>>> x = Int('x')

Traceback (most recent call last):
[...]
  File "C:\Program Files\Microsoft Research\Z3-4.0\python\z3core.py", line 34, in init
    _lib = ctypes.CDLL(PATH)
  File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

Anyone know what the problem could be? 有人知道可能是什么问题吗?

My PYTHONPATH is set to "C:\\Program Files\\Microsoft Research\\Z3-4.0\\python", without the quotes. 我的PYTHONPATH设置为“ C:\\ Program Files \\ Microsoft Research \\ Z3-4.0 \\ python”,不带引号。

Z3 uses thread local storage. Z3使用线程本地存储。 It is implemented using __declspec(thread). 它是使用__declspec(thread)实现的。 Unfortunately, this is not supported by DLLs in Windows XP and Server 2003. From MSN documentation: 不幸的是,Windows XP和Server 2003中的DLL不支持此功能。从MSN文档:

"For DLLs that are loaded dymanically after the process has started (delay load, COM objects, explicit LoadLibrary, etc) __declspec(thread) does not work on Windows XP, 2003 Server and earlier OSes, but does work on Vista and 2008 Server." “对于在过程开始后动态加载的DLL(延迟加载,COM对象,显式LoadLibrary等),__ declspec(thread)在Windows XP,2003 Server和早期版本的OS上不起作用,但在Vista和2008 Server上起作用。 ”

So, to use the Z3 DLL, you must use one of the following Windows: 8, 7, Vista or Server 2008. 因此,要使用Z3 DLL,必须使用以下Windows之一:8、7,Vista或Server 2008。

On Windows XP there may be a problem with spaces in file names such that python cannot find z3.dll; 在Windows XP上,文件名中的空格可能存在问题,使得python无法找到z3.dll。 this seems to be a general python issue, see, eg: some notes on PYTHONPATH 这似乎是一个通用的python问题,请参见,例如: 关于PYTHONPATH的一些说明

It may work if the old 8.3-format for directories is used. 如果使用目录的旧8.3格式,则可能会起作用。 You can find the short names by finding the Z3 directory in a command shell (I use dir /x to see the short names on Windows 7) and on my system the short path is C:\\progra~1\\mi4430~1\\z3-4.0\\bin. 您可以通过在命令外壳中找到Z3目录来找到短名称(我使用dir / x在Windows 7上查看短名称),而在我的系统上,短路径为C:\\ progra〜1 \\ mi4430〜1 \\ z3 -4.0 \\ bin。 These numbers are different on every installation though. 但是,这些数字在每个安装中都不同。

A quicker solution may be to simply copy z3.dll from the bin directory to the python directory (or from the x64 directory if you're on 64-bit). 更快的解决方案是将z3.dll从bin目录复制到python目录(如果使用64位,则从x64目录复制)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM