简体   繁体   English

如何在 Linux 中为 Python3 安装 Z3

[英]How to install Z3 for Python3 in Linux

I'm trying to run a program in python3 that has Z3 as a dependency (imports z3)我正在尝试在 python3 中运行一个以 Z3 作为依赖项的程序(导入 z3)

I was able to install the unstable version of Z3 (which is suppose to support Python3), but it install the libraries for python2.7 only.我能够安装 Z3 的不稳定版本(假设它支持 Python3),但它只安装了 python2.7 的库。

Here are the instructions at the project:以下是项目中的说明

python scripts/mk_make.py
cd build
make
sudo make install

Does anybody know how to install Z3 work for Python3?有人知道如何为 Python3 安装 Z3 工作吗?

Thanks.谢谢。

I had to modify scripts/mk_util.py in order to convert a few lines from Python2 to Python3 and also replace tab with spaces in other few lines, after that it worked!. 我不得不修改scripts / mk_util.py,以便将几行代码从Python2转换为Python3,并且还用其他几行中的空格替换tab,在那之后它起作用了!

It seems somebody accidentally introduced changes not compatible with Python3. 似乎有人不小心引入了与Python3不兼容的更改。

I noticed Leonardo de Moura about this and he made a change in z3 git repo. 我注意到莱昂纳多·德·穆拉(Leonardo de Moura) ,他改变了z3 git repo。

Here's a path just in case 这是一条路,以防万一

--- z3-original/scripts/mk_util.py
+++ z3/scripts/mk_util.py
@@ -640,7 +640,7 @@

 def is_clang_in_gpp_form(cc):
     version_string = subprocess.check_output([cc, '--version'])
-    return version_string.find('clang') != -1
+    return str(version_string).find('clang') != -1

 def is_CXX_clangpp():
     if is_compiler(CXX, 'g++'):
@@ -1485,7 +1485,7 @@
                 print('Java Compiler:  %s' % JAVAC)
     else:
         global CXX, CC, GMP, FOCI2, CPPFLAGS, CXXFLAGS, LDFLAGS, EXAMP_DEBUG_FLAG
-   OS_DEFINES = ""
+        OS_DEFINES = ""
         ARITH = "internal"
         check_ar()
         CXX = find_cxx_compiler()
@@ -1508,7 +1508,7 @@
                 SLIBEXTRAFLAGS = '%s %s' % (SLIBEXTRAFLAGS,FOCI2LIB)
                 CPPFLAGS = '%s -D_FOCI2' % CPPFLAGS
             else:
-                print "FAILED\n"
+                print("FAILED\n")
                 FOCI2 = False
         if GIT_HASH:
             CPPFLAGS = '%s -DZ3GITHASH=%s' % (CPPFLAGS, GIT_HASH)
@@ -1536,21 +1536,21 @@
             SLIBFLAGS = '-dynamiclib'
         elif sysname == 'Linux':
             CXXFLAGS       = '%s -fno-strict-aliasing -D_LINUX_' % CXXFLAGS
-       OS_DEFINES     = '-D_LINUX'
+            OS_DEFINES     = '-D_LINUX'
             SO_EXT         = '.so'
             LDFLAGS        = '%s -lrt' % LDFLAGS
             SLIBFLAGS      = '-shared'
             SLIBEXTRAFLAGS = '%s -lrt' % SLIBEXTRAFLAGS
         elif sysname == 'FreeBSD':
             CXXFLAGS       = '%s -fno-strict-aliasing -D_FREEBSD_' % CXXFLAGS
-       OS_DEFINES     = '-D_FREEBSD_'
+            OS_DEFINES     = '-D_FREEBSD_'
             SO_EXT         = '.so'
             LDFLAGS        = '%s -lrt' % LDFLAGS
             SLIBFLAGS      = '-shared'
             SLIBEXTRAFLAGS = '%s -lrt' % SLIBEXTRAFLAGS
         elif sysname[:6] ==  'CYGWIN':
             CXXFLAGS    = '%s -D_CYGWIN -fno-strict-aliasing' % CXXFLAGS
-       OS_DEFINES     = '-D_CYGWIN'
+            OS_DEFINES     = '-D_CYGWIN'
             SO_EXT      = '.dll'
             SLIBFLAGS   = '-shared'
         else:
@@ -1586,7 +1586,7 @@
         config.write('SLINK_FLAGS=%s\n' % SLIBFLAGS)
         config.write('SLINK_EXTRA_FLAGS=%s\n' % SLIBEXTRAFLAGS)
         config.write('SLINK_OUT_FLAG=-o \n')
-   config.write('OS_DEFINES=%s\n' % OS_DEFINES)
+        config.write('OS_DEFINES=%s\n' % OS_DEFINES)
         if is_verbose():
             print('Host platform:  %s' % sysname)
             print('C++ Compiler:   %s' % CXX)

For anyone who is wondering about this later on.对于以后对此感到疑惑的任何人。

I created an alias from 'python' to 'python3' and then ran the install command on the z3 git repo.我创建了一个从“python”到“python3”的别名,然后在 z3 git repo 上运行了 install 命令。

alias python=python3 #alias for the script to use.
python scripts/mk_make.py --prefix=/home/leo
cd build
make
make install

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

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