I've installed z3-solver package from PyPi in my Python3 environment using Anaconda Prompt ( pip install z3-solver ) and that's it.
The package appears in the site-packages/ directory ( the package has _init__.py and all essential files including z3.py ). However, when I tried running this example from Jupyter Notebook, it returns the following message: NameError: name 'Int' is not defined.
I've only used Anaconda for a short time so I'm not sure how installation works. It's really odd because the 'pip install' command works fine most of the times. Did I do something wrong or this package requires more configuration ?
-
Change Int to int – uttejh Apr 12 '20 at 12:40
-
It doesn't work. Int is a class defined in z3 and the example I used is taken from their official Github repo so it's not realated to the syntax. – CPS_001 Apr 12 '20 at 13:01
-
1Do you have a file named `z3.py` in your project directory? – sepp2k Apr 12 '20 at 15:15
-
Did you follow the recommendations for using pip with Conda? See, for example: https://www.anaconda.com/using-pip-in-a-conda-environment/. – AMC Apr 16 '20 at 02:30
5 Answers
you have to write:
from z3 import *
which solved my NameError: name 'Solver' is not defined
Exception
prerequisites:
pip install z3
pip install z3-solver
code example
from z3 import *
def main():
s = Solver()
x = Int('x')
y = Int('y')
s.add(x < 10)

- 834
- 2
- 12
- 36
-
Installing the "z3" package is a mistake. "z3" is an old package for doing a compressed backup to or from AWS servers, unrelated to "z3-solver". – Charles Merriam Sep 03 '23 at 04:14
Sorry for the late update.
I've managed to solve the problem based on this guide.
To permanently change the sys.path
variable in Anaconda,
I created a .PTH file
which contains the path to z3
and put it in site-packages directory.
You might need to copy the libz3.dll
file to the right directory in order for it to work.
Running pip install z3-solver
does download the required files and put them in site-packages but I can't import z3
from anywhere.
Maybe you also need to fix the path after using pip so Anaconda can recognize it. I did everything manually so I'm not sure why pip doesn't work in this case.
That's all I did to install z3
on my Windows
. Hope it helps !
Had the same problem in 2022.
IMPORTANT:
Install using the following command
pip install z3 z3-solver
I did not know about the z3-solver package so I installed it later but it didn't work. Same issue as you. Could import but the import only included half a dozen special dunder functions like __file__
and others.
After all permutes of install, uninstall, add-to-$PATH ... later I just did this and it worked at once.

- 91
- 1
- 4
Lots of answers, but I had this problem and found:
- First,
pip install z3
installs an obsolete and unrelated package related to AWS backups. - Second,
pip install z3-solver
installs only the interface to an installed installation of the z3 system, under the python library namez3
. It does not install the underlying z3 system and it does warn you that it does not exist. If there is no underlying system, "import * from z3" will execute, but not import any useful functions. - Third, the easiest way to install z3 is use your favorite package manager. On macOS, I used
brew install z3
.
When the installation of both parts works, a good quick test is import * from z3; a,b = Reals('a b')
. If these statements execute, you are good.

- 19,908
- 6
- 73
- 83