How to run Gurobi throught Julia

To install Julia, we can download it from github

git clone
cd julia
sudo apt-get install build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config
make -j8
make install
cd julia-*
cd bin

Now, export the working directory to your .bashrc file

export PATH="$(pwd)/julia:$PATH"

Run julia and add JuMP (Julia for Mathematical Programming):

WARNING: Base.Pkg is deprecated, run `using Pkg` instead

After a while I could'nt install it. To avoid warnings and issues I installed the last stable version:

tar xzvf julia-0.6.2-full.tar.gz
cd julia-0.6.2
make -j8
make install
cd julia-*
cd bin

Export to the bashrc file again and install the package:


Maybe you can have issues to load gurobi if the environment is not configured:

using Gurobi
INFO: Precompiling module Gurobi.
ERROR: LoadError: Gurobi not properly installed. Please run"Gurobi")

 [1] error(::String) at ./error.jl:21
 [2] include_from_node1(::String) at ./loading.jl:576
 [3] include(::String) at ./sysimg.jl:14
 [4] anonymous at ./<missing>:2
while loading /home/dragonx/.julia/v0.6/Gurobi/src/Gurobi.jl, in expression starting on line 8
ERROR: Failed to precompile Gurobi to /home/dragonx/.julia/lib/v0.6/Gurobi.ji.
 [1] compilecache(::String) at ./loading.jl:710
 [2] _require(::Symbol) at ./loading.jl:497
 [3] require(::Symbol) at ./loading.jl:405



INFO: Building Gurobi
===============================[ ERROR: Gurobi ]================================

LoadError: Unable to locate Gurobi installation. Note that this must be downloaded separately from
while loading /home/dragonx/.julia/v0.6/Gurobi/deps/build.jl, in expression starting on line 42


================================[ BUILD ERRORS ]================================

WARNING: Gurobi had build errors.

 - packages with build errors remain installed in /home/dragonx/.julia/v0.6
 - build the package(s) and all dependencies with `"Gurobi")`
 - build a single package by running its `deps/build.jl` script


Check if gurobi environment is configured:

ERROR: KeyError: key "GUROBI_HOME" not found
 [1] access_env(::Base.##288#289, ::String) at ./env.jl:45
 [2] getindex(::Base.EnvHash, ::String) at ./env.jl:78

As you can see, Julia not recognize PATH to Gurobi_Home. Then you need to declare it:

julia> ENV["GUROBI_HOME"] = "/path/to/gurobi/linux64"
INFO: Building Gurobi

julia> Pkg.add("Gurobi")
INFO: Package Gurobi is already installed

julia> using Gurobi
INFO: Precompiling module Gurobi.

Now, create an example.jl (julia file) with and example:

using JuMP, Gurobi

m = Model(solver=GurobiSolver(ResultFile="solution.sol",OutputFlag=0))

@variable(m, x >= 5)
@variable(m, y >= 45)

@objective(m, Min, x + y)
@constraint(m, 50x + 24y <= 2400)
@constraint(m, 30x + 33y <= 2100)

status = solve(m)

And we run it from julia:

julia example.jl

The output is in solution.sol to import it from any other language like python

sudo pip3 install julia

Enjoy it!


Popular posts from this blog

from: can't read /var/mail/ in Python scripts

How to fix Android when developer options are not available for this user

Fix "Set scan parameters failed: Input/output error" on Ubuntu 16.04