4

I can not get any of the z3py examples to work. I was able to install it successful using the instructions from the README on github. I successfully updated my python path to point to the appropriate directory. Furthermore, I was able to successfully import z3, but I get an error every time I declare a variable. The compiler does not recognize Int, Ints, Real , RealVal.

I have included an example to illustrate.

Code:

from z3 import *
x = Int('x')
y = Int('y')
solve(x > 2, y < 10, x + 2*y == 7)

Error: Traceback (most recent call last): File "test.py", line 3, in x = Int('x') NameError: name 'Int' is not defined

I would really appreciate any help. Thank you so much.

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • What does `dir()` show you after `from z3 import *` ? Have you instead tried `import z3; x = z3.Int('x')` ? – nekomatic Jun 17 '16 at 08:02
  • @nekomantic: Thanks for your response. Here are the answers: `from z3 import * dir() >>>['__builtins__', '__doc__', '__name__', '__package__'] >>> x = Int('x') Traceback (most recent call last): File "", line 1, in NameError: name 'Int' is not defined` `>>> import z3 >>> x = Int('x') Traceback (most recent call last): File "", line 1, in NameError: name 'Int' is not defined` – Akanksha Vyas Jun 18 '16 at 09:28
  • After you `import` a module it should appear in the result of `dir()`, so I would check whether you've installed z3 properly. – nekomatic Jun 19 '16 at 20:29
  • @nekomantic I fixed that and the same problem persists even though it is seems to be importing properly. Here is the result. Thank you, again: `>>> import z3 >>> dir() ['__builtins__', '__doc__', '__name__', '__package__', '__warningregistry__', 'z3'] >>> x = Int('x') Traceback (most recent call last): File "", line 1, in NameError: name 'Int' is not defined` – Akanksha Vyas Jun 20 '16 at 09:01
  • 1
    Please read my suggestion carefully: if you have done `import z3` then try `x = z3.Int('x')`, and so on. – nekomatic Jun 20 '16 at 10:27
  • 1
    Do you have `z3.py` in your working dir? It shadows installed package. – Łukasz Rogalski Jun 23 '16 at 17:28
  • It finally works after a clean installation. Thank you for all your help. – Akanksha Vyas Jun 25 '16 at 11:31

2 Answers2

0

There is something wrong with your local installation, either of Python or Z3.

I just compiled Z3 on my Mac and ran the example test.py you provided with no problems. I'm using OS X 10.9.5 with Python 2.7.11 and the current master version of Z3 (commit 41edf5f). The exact instructions I used were:

git clone https://github.com/Z3Prover/z3.git
cd z3
./configure
cd build
make -j4
emacs test.py
# Write in the example you gave.
python ./test.py

The output I got was [y = 0, x = 7], which is the same output that I got from your script on my Linux box. So the problem is specific to your OS X machine or build procedure.

Douglas B. Staple
  • 10,510
  • 8
  • 31
  • 58
0

Try to install z3-solver: pip install z3-solver

There's a name conflict with z3

Guillot
  • 1
  • 1