Gurobi support for Python 3.5

4,284 views
Skip to first unread message

David Myers

unread,
Jul 18, 2016, 12:08:23 PM7/18/16
to Gurobi Optimization
Just wondering if there were any plans for Gurobi to support the use of Python 3.5.

Thanks in advance for any help.

--David

Wilmer Henao

unread,
Jul 20, 2016, 11:32:46 AM7/20/16
to Gurobi Optimization
Hi David. I have been using python 3.5 for a couple of days already. It seems like they just updated their documentation. Look at page 99 of the windows manual (also in linux). http://www.gurobi.com/documentation/6.5/quickstart_windows.pdf

Monique Bakker

unread,
Aug 15, 2016, 12:24:38 AM8/15/16
to Gurobi Optimization
I saw that Gurobi now supports Python 3.5 on Windows 64 bit. But I can't get it to work, keep getting the error  

ImportError: No module named 'gurobipy'

Also when I open Gurobi the console shows that Python 2.7.8 is the default. How do I change this? Do I need to upgrade Gurobi? (academic license)

Thanks!

Sonja Mars

unread,
Aug 15, 2016, 5:26:34 AM8/15/16
to gur...@googlegroups.com
Hi,

> I saw that Gurobi now supports Python 3.5 on Windows 64 bit. But I can't get it to work, keep getting the error
>
> ImportError: No module named 'gurobipy'
You will first have to install Gurobi into this specific Python version. If this is Anaconda Python, please follow the instructions under "Step 2" on this page: http://www.gurobi.com/documentation/6.5/quickstart_windows/installing_the_anaconda_py.html#section:Anaconda.
For other Python distributions see here: https://www.gurobi.com/documentation/6.5/quickstart_windows/the_gurobi_python_interfac.html

> Also when I open Gurobi the console shows that Python 2.7.8 is the default. How do I change this? Do I need to upgrade Gurobi? (academic license)
This is the Python version that comes with Gurobi, you cannot change this.

Best regards,
Sonja

-----------------------------------------------------------------
Dr. Sonja Mars
Gurobi Optimization
ma...@gurobi.de
-----------------------------------------------------------------
Gurobi Optimizer 6.5 — State-of-the-art performance and best-in-class support
for your most important problems. Learn more at www.gurobi.com.



Enrique Fernández

unread,
Aug 18, 2016, 10:57:09 AM8/18/16
to Gurobi Optimization
When can we expect Python 3.5 support for OSX?

According to Python developers, no new projects should be started in Python2, as it is approaching its end of life.
Gurobi is the only package that I need that does not support Python3.

Thanks!

Sonja Mars

unread,
Oct 27, 2016, 6:00:44 AM10/27/16
to gur...@googlegroups.com
Hi,

We just released Gurobi version 7.0. This version now supports Python 3.5 on Mac.

Best regards,
Sonja


----
Dr. Sonja Mars
Gurobi Optimization - Technical Support

Enrique Fernández

unread,
Oct 27, 2016, 11:20:55 AM10/27/16
to Gurobi Optimization
Awesome. Thanks!

fernando...@uas.edu.mx

unread,
Oct 28, 2016, 8:13:10 PM10/28/16
to Gurobi Optimization
Hi Enrique and Sonja,

Have you already installed Gurobi 7.0 and used Python 3.5? I have some problems for installing gurobi on Anaconda (Python 3.5). When I run this command, I got this:

>>> conda config --add channels http://conda.anaconda.org/gurobi
  File "<stdin>", line 1
    conda config --add channels http://conda.anaconda.org/gurobi
               ^
SyntaxError: invalid syntax

Any solution?

Renan Garcia

unread,
Oct 29, 2016, 7:43:44 AM10/29/16
to gur...@googlegroups.com
This error is due to the fact that you are running the conda command from within the Python shell. You should be running it from an ordinary command prompt.

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

fernando...@uas.edu.mx

unread,
Nov 1, 2016, 1:56:26 AM11/1/16
to Gurobi Optimization
Hi there,

When I ran the conda command on an ordinary command prompt it worked...but, now, when I want to run a gurobi program on spyder I have this:

runfile('/Users/DrFernando/.spyder-py3/temp.py', wdir='/Users/DrFernando/.spyder-py3')
Traceback (most recent call last):

  File "<ipython-input-1-8f573f30d3da>", line 1, in <module>
    runfile('/Users/DrFernando/.spyder-py3/temp.py', wdir='/Users/DrFernando/.spyder-py3')

  File "/Users/DrFernando/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "/Users/DrFernando/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/Users/DrFernando/.spyder-py3/temp.py", line 2, in <module>
    from gurobipy import *

  File "/Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/__init__.py", line 1, in <module>
    from .gurobipy import *

ImportError: dlopen(/Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/gurobipy.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.5/Python
  Referenced from: /Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/gurobipy.so
  Reason: image not found



I thought then, that I have to run in the python console the command "import gurobipy", and I have this:


import gurobipy
Traceback (most recent call last):

  File "<ipython-input-2-1a30be95fe9a>", line 1, in <module>
    import gurobipy

  File "/Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/__init__.py", line 1, in <module>
    from .gurobipy import *

ImportError: dlopen(/Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/gurobipy.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.5/Python
  Referenced from: /Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/gurobipy.so
  Reason: image not found



I also tried this:


from gurobipy import *
Traceback (most recent call last):

  File "<ipython-input-3-ef341d965cc7>", line 1, in <module>
    from gurobipy import *

  File "/Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/__init__.py", line 1, in <module>
    from .gurobipy import *

ImportError: dlopen(/Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/gurobipy.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.5/Python
  Referenced from: /Users/DrFernando/anaconda/lib/python3.5/site-packages/gurobipy/gurobipy.so
  Reason: image not found


I would really appreciate your help, I´am novice using Gurobi. 

Sonja Mars

unread,
Nov 3, 2016, 4:52:37 AM11/3/16
to gur...@googlegroups.com
Hi,

Did you execute the following two commands in a command prompt:

conda config --add channels http://conda.anaconda.org/gurobi
conda install gurobi

If this was successful, open a python shell by typing 
python 
in the command prompt and then
from gurobipy import *
Is this working for you? if not, can you send a screenshot of showing this?

Thanks and best regards, 

Jeremy Zucker

unread,
Nov 9, 2016, 12:37:18 AM11/9/16
to Gurobi Optimization
Hi folks,

I have installed previous versions of gurobi on a mac, but now I am trying to install gurobi 7 using anaconda:


When I tried to install gurobi using anaconda, and got the following error:

bash$ conda config --add channels http://conda.anaconda.org/gurobi
bash$ conda install gurobi
conda install gurobi
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata .............Error: Invalid index file: http://conda.anaconda.com/gurobi/osx-64/repodata.json: Expecting value: line 1 column 1 (char 0)

bash$ python
Python 3.5.2 |Anaconda 2.5.0 (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Any advice would be appreciated.

Sincerely,

Jeremy

Jeremy Zucker

unread,
Nov 9, 2016, 12:37:18 AM11/9/16
to Gurobi Optimization
Upgraded to Anaconda3-4.0.0
and now this is the error:

bash$ conda install gurobi
conda install gurobi
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ..........An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:


Include the output of the command 'conda info' in your report.


Traceback (most recent call last):
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/bin/conda", line 6, in <module>
    sys.exit(main())
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/cli/main.py", line 139, in main
    args_func(args, p)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/cli/main.py", line 146, in args_func
    args.func(args, p)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/cli/main_install.py", line 62, in execute
    install.install(args, parser, 'install')
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/cli/install.py", line 240, in install
    prefix=prefix)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/cli/common.py", line 595, in get_index_trap
    return get_index(*args, **kwargs)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/api.py", line 43, in get_index
    unknown=unknown)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/utils.py", line 118, in __call__
    value = self.func(*args, **kw)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/fetch.py", line 259, in fetch_index
    repodatas.append((url, future.result()))
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/concurrent/futures/_base.py", line 398, in result
    return self.__get_result()
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/fetch.py", line 65, in func
    res = f(*args, **kwargs)
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/conda/fetch.py", line 103, in fetch_repodata
    cache = json.loads(bz2.decompress(resp.content).decode('utf-8'))
  File "/Users/zuck016/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/bz2.py", line 348, in decompress
    res = decomp.decompress(data)
OSError: Invalid data stream


(anaconda3-4.0.0) bash-3.2$ conda info
conda info
Using Anaconda Cloud api site https://api.anaconda.org
Current conda install:

             platform : osx-64
        conda version : 4.0.5
  conda-build version : 0+unknown
       python version : 3.5.1.final.0
     requests version : 2.9.1
     root environment : /Users/zuck016/.pyenv/versions/anaconda3-4.0.0  (writable)
  default environment : /Users/zuck016/.pyenv/versions/anaconda3-4.0.0
     envs directories : /Users/zuck016/.pyenv/versions/anaconda3-4.0.0/envs
        package cache : /Users/zuck016/.pyenv/versions/anaconda3-4.0.0/pkgs
         channel URLs : http://conda.anaconda.org/gurobi/osx-64/
                        http://conda.anaconda.org/gurobi/noarch/
                        http://conda.anaconda.com/gurobi/osx-64/
                        http://conda.anaconda.com/gurobi/noarch/
                        https://conda.anaconda.org/bioconda/osx-64/
                        https://conda.anaconda.org/bioconda/noarch/
                        https://conda.anaconda.org/r/osx-64/
                        https://conda.anaconda.org/r/noarch/
                        https://repo.continuum.io/pkgs/free/osx-64/
                        https://repo.continuum.io/pkgs/free/noarch/
                        https://repo.continuum.io/pkgs/pro/osx-64/
                        https://repo.continuum.io/pkgs/pro/noarch/
          config file : /Users/zuck016/.condarc
    is foreign system : False

(anaconda3-4.0.0) bash-3.2$ 

On Thursday, November 3, 2016 at 1:52:37 AM UTC-7, Sonja Mars wrote:

Sonja Mars

unread,
Nov 9, 2016, 12:56:00 AM11/9/16
to gur...@googlegroups.com
Hi,

It seems you have added the Gurobi channel twice:
http://conda.anaconda.org/gurobi/osx-64/
                        http://conda.anaconda.org/gurobi/noarch/
                        http://conda.anaconda.com/gurobi/osx-64/
                        http://conda.anaconda.com/gurobi/noarch/


And one of the errors you are seeing, is because 
don't exist, please remove those and always use those with .org instead. Removing channels can be done with this command:
conda config --remove channels http://conda.anaconda.com/gurobi
More details about conda can be found here: 

Additionally, it looks like you are using Anaconda cloud. 

Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ..........
Maybe you should consider contacting conda like proposed here:
An unexpected error has occurred, please consider sending the
following traceback to the conda GitHub issue tracker at:

    https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.

This does not look like a Gurobi issue. 

Best regards, 

Marko Budinich

unread,
Nov 25, 2016, 2:16:37 AM11/25/16
to Gurobi Optimization
Hi everyone,

I use OSX 10.11.6 (El Capitan) and recently updated from gurobi version 6.0.4 to version 7.0.1 and from python 2.7 to python 3.5 using MacPorts. When installing gurobipy (using setup.py), got the following error:

ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/gurobipy/gurobipy.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.5/Python
  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/gurobipy/gurobipy.so
  Reason: image not found


I solved by either creating a symbolic link to library:

sudo mkdir -p /Library/Frameworks/Python.framework/Versions/3.5/
sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/3.5/Python /Library/Frameworks/Python.framework/Versions/3.5/Python


or a direct call on install_name_tool:

sudo install_name_tool -change /Library/Frameworks/Python.framework/Versions/3.5/Python /opt/local/Library/Frameworks/Python.framework/Versions/3.5/Python /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/gurobipy/gurobipy.so

I post it here in case anyone runs over the same problem.

Cheers,
Marko

x.man...@gmail.com

unread,
Oct 25, 2017, 2:38:02 PM10/25/17
to Gurobi Optimization
OSX El Capitan
Gurobi 7.5

trying to install Gurobi on python 3.6, I get following error:

(python3env)$ python3 setup.py install
running install
running build
running build_py
error: package directory 'lib/python3.6/gurobipy' does not exist

any hints to fix this?

Rennan Chagas

unread,
Oct 26, 2017, 3:17:00 PM10/26/17
to Gurobi Optimization
I had problems to use gurobipy with python 3.6. I tried Marko's suggestion but did not work.

Check If you can use gurbi command line with gurobi.ch terminal command. If so, you can use with python2. That actually worked for me after running python2 setup install

 Now I am using gurobi and gurobipy with python 2. In order to not have to rebuild all your projects to python2 you just have to add this code lines in the beginning of your files and you'll be able to code with python 3 syntax


from __future__ import (absolute_import, division, print_function,
generators, nested_scopes, unicode_literals, with_statement)

Enrique Fernández

unread,
Oct 26, 2017, 3:36:48 PM10/26/17
to Gurobi Optimization
I've actually been using python 3.6 with Gurobi 7.5 for quite some time and it's worked great.
I recommend people use Anaconda and install Gurobi with conda as indicated in the Gurobi documentation.
No issues whatsoever in either OSX 10.11 El Capitan, or 10.12 Sierra.

x.man...@gmail.com

unread,
Oct 28, 2017, 11:17:10 AM10/28/17
to Gurobi Optimization

Thanks Enrique.  if possible I am hoping to make it work with pip. mixing up pip and conda has not worked well for me in the past. 

x.man...@gmail.com

unread,
Oct 28, 2017, 11:17:10 AM10/28/17
to Gurobi Optimization
Thanks Rennan,  That's good to know. I have gurobipy working in python2 , but wanted to upgrade my codebase to python3, for reasons related to joblib's performance features that are not being ported to python2 (https://github.com/scikit-learn/scikit-learn/issues/3835).


On Thursday, October 26, 2017 at 3:17:00 PM UTC-4, Rennan Chagas wrote:
Reply all
Reply to author
Forward
0 new messages