Emily
Emily

Reputation: 21

Can't find MiniZinc driver

I'm trying to run a Python script on Ubuntu that uses the minizinc module.

The script runs fine on a Windows machine. However, when I try to run the same script on Ubuntu, I get the following error:

RuntimeWarning: MiniZinc was not found on the system. No default driver could be initialized.

The minizinc module documentation warns about this error on Linux systems and states that the path to the driver can manually be provided using minizinc.find_driver() function. I've attempted to manually set the driver path using that function but the same error occurs (I'm maybe setting it the wrong way).

I'm new to this as you can probably tell and am just wondering if anyone can enlighten me as to how to fix this issue?

Upvotes: 0

Views: 867

Answers (1)

Dekker1
Dekker1

Reputation: 5786

There are two ways to make MiniZinc Python aware of where MiniZinc was installed:

  • You can append your PATH environment variable with the directory where the minizinc executable was installed.
  • You can select a specific driver using the find_driver function and then use the make_default method on Driver object that is returned.

For either method you first need to find where you have installed the minizinc executable. If you installed using the AppImage, then you can create a symlink:

$ ln -s MiniZinc<something>.AppImage /my/path/to/minizinc

This symlink will then function as the MiniZinc executable. In the following examples I will use /my/path/to/minizinc as the location of MiniZinc, but you find where it is on your own computer.

Method 1

Using the first method is usually preferred unless you want to use multiple versions of MiniZinc. If you have a MiniZinc Python script script.py that you want to execute. You simply first add the executable location to the PATH environment variable, and then run your script.

$ export PATH=$PATH:/my/path/to
$ python script.py

You only have to set the PATH once per terminal session, so afterwards you can just repeatedly run the second line. If you use MiniZinc often, then it might be a good idea to this export line to you .bashrc (or depending on what shell you use a different file).

Method 2

The other method is to edit your MiniZinc Python script. Where you used to have

import minizinc

[SOMETHING]

You would now write

import minizinc

my_driver = minizinc.find_driver("/my/path/to")
my_driver.make_default()

[SOMETHING]

To make sure it found the executable you can even add print(my_driver) so see which MiniZinc executable it found.

Note that this method will still give you a warning since, at import time, MiniZinc Python cannot find the driver. It also makes your Python code less portable, since someone else might have installed MiniZinc in a different location.

Upvotes: 3

Related Questions