installing Gurobi in Python virtualenv

601 views
Skip to first unread message

Jennifer Gossels

unread,
Jan 3, 2019, 5:40:24 AM1/3/19
to Gurobi Optimization
Hello,

I'm trying to use Gurobi on a shared university Linux machine to which I don't have sudo access.  Gurobi is installed, and it works fine with the regular python on the system.  But, I need to use a virtualenv to get the correct versions of other Python packages my code relies on.  As soon as I activate my virtualenv, Gurobi no longer works.  Specifically, when I bring up a Python interpreter and try import gurobipy I get "ImportError:  No module named gurobipy"  I can't just navigate to the Gurobi directory and run setup.py install, because it says I don't have permission.  How can I fix this problem?

Thanks,
Jennifer

---------------

No virtualenv; Gurobi works but NetworkX doesn't:

[jgossels@node302 src]$ python

Python 2.7.5 (default, Jul  3 2018, 19:30:05) 

[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import gurobipy

>>> import networkx

/usr/lib64/python2.7/site-packages/scipy/__init__.py:115: UserWarning: Numpy 1.8.2 or above is recommended for this version of scipy (detected version 1.7.1)

  UserWarning)

RuntimeError: module compiled against API version 9 but this version of numpy is 7

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/lib/python2.7/site-packages/networkx/__init__.py", line 114, in <module>

    import networkx.generators

  File "/usr/lib/python2.7/site-packages/networkx/generators/__init__.py", line 14, in <module>

    from networkx.generators.intersection import *

  File "/usr/lib/python2.7/site-packages/networkx/generators/intersection.py", line 13, in <module>

    from networkx.algorithms import bipartite

  File "/usr/lib/python2.7/site-packages/networkx/algorithms/__init__.py", line 62, in <module>

    import networkx.algorithms.community

  File "/usr/lib/python2.7/site-packages/networkx/algorithms/community/__init__.py", line 20, in <module>

    from networkx.algorithms.community.community_generators import *

  File "/usr/lib/python2.7/site-packages/networkx/algorithms/community/community_generators.py", line 18, in <module>

    from scipy.special import zeta as _zeta

  File "/usr/lib64/python2.7/site-packages/scipy/special/__init__.py", line 640, in <module>

    from ._ufuncs import *

  File "__init__.pxd", line 872, in init scipy.special._ufuncs

ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 176, got 192

>>> 


virtualenv; NetworkX works but Gurobi doesn't:

[jgossels@node302 src]$ source my_py27_venv/bin/activate

(my_py27_venv) [jgossels@node302 src]$ python

Python 2.7.5 (default, Jul  3 2018, 19:30:05) 

[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import networkx

>>> import gurobipy

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ImportError: No module named gurobipy

>>> 

Silke Horn

unread,
Jan 3, 2019, 5:49:47 AM1/3/19
to gur...@googlegroups.com
Hi Jennifer,

To install the Gurobi Python module you need write permissions in the Gurobi directory. You could install Gurobi again in your home directory and then run setup.py there in order to install the module in your virtual environment.

- Silke
> --
>
> ---
> 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.

Robert Luce

unread,
Jan 6, 2019, 11:53:43 PM1/6/19
to Gurobi Optimization
Hello Jennifer,

by default virtual environments don't "see" site-packages of their parent.  Please simply reinstall gurobipy using the python interpreter of your virutal environment by following the instructions at the end of


Typically all you need to do is

(venv) bash-3.2$ cd /Library/gurobi810/mac64/
(venv) bash-3.2$ python setup.py install

Best,

Robert
Reply all
Reply to author
Forward
0 new messages