メインコンテンツへスキップ

no module name 'gurobipy'

回答済み

コメント

14件のコメント

  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    You need to do one more step to use Gurobi in Jupyter.

    From the Quick Start Guide:http://www.gurobi.com/documentation/8.1/quickstart_mac/py_building_and_running_th.html

    > You can also install the gurobipy module directly into other Python environments. The steps for doing this depend on your platform. On Mac OS, you will need to open a terminal window, change your current directory to the Gurobi <installdir> (the directory that contains the file setup.py), and issue the following command:

    python setup.py install

    1
  • parfait atchadé
    Gurobi-versary
    Conversationalist
    First Question

    Many thanks Gwyneth!!!

    It's amazing...  It seems that I don't have the setup.py file

     

    exec gurobi.sh

    Last login: Fri May 17 18:51:03 on ttys001

    MacBook-Air-BCG:~ parfait$ exec gurobi.sh

    Python 2.7.10 (default, Aug 17 2018, 17:41:52)

    [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin

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

     

    Gurobi Interactive Shell (mac64), Version 8.1.1

    Copyright (c) 2018, Gurobi Optimization, LLC

    Type "help()" for help

     

    gurobi> python setup.py install

      File "<stdin>", line 1

        python setup.py install

                   ^

    SyntaxError: invalid syntax

    gurobi>

     

    0
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    To run the setup script, navigate to the directory where you installed Gurobi, such as /Library/gurobi811/mac64/

    From the terminal prompt there, run the command python setup.py install.

    For example:

    bash-3.2$ cd /Library/gurobi811/mac64/
    bash-3.2$ python setup.py install

    I hope this helps.

     

     

    0
  • parfait atchadé
    Gurobi-versary
    Conversationalist
    First Question

    I was on the wrong path...  

    running install

    running build

    running build_py

    creating build

    creating build/lib

    creating build/lib/gurobipy

    copying lib/python2.7/gurobipy/__init__.py -> build/lib/gurobipy

    copying lib/python2.7/gurobipy/gurobipy.so -> build/lib/gurobipy

    running install_lib

    running install_egg_info

    Removing /Library/Python/2.7/site-packages/gurobipy-8.1.1-py2.7.egg-info

    error: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/gurobipy-8.1.1-py2.7.egg-info'

    0
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    I believe this problem is because you may need to run the command as a super-user:

     

    From the Quick Start Guide (http://www.gurobi.com/documentation/8.1/quickstart_mac/py_building_and_running_th.html):

    python setup.py install

    Unless you are using your own private Python installation, you will need to run this command as super-user.

    0
  • parfait atchadé
    Gurobi-versary
    Conversationalist
    First Question

    Thanks!!

    Yes!! Done!!

    sh-3.2# python setup.py install

    running install

    running build

    running build_py

    creating build

    creating build/lib

    creating build/lib/gurobipy

    copying lib/python2.7/gurobipy/__init__.py -> build/lib/gurobipy

    copying lib/python2.7/gurobipy/gurobipy.so -> build/lib/gurobipy

    running install_lib

    running install_egg_info

    Removing /Library/Python/2.7/site-packages/gurobipy-8.1.1-py2.7.egg-info

    Writing /Library/Python/2.7/site-packages/gurobipy-8.1.1-py2.7.egg-info

    removing /Library/gurobi811/mac64/build

     

    But the module is still not found! I set up the PATH ;( 

    ModuleNotFoundError: No module named 'gurobipy'
    0
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    I suspect that perhaps your Jupyter is using a different Python than the one that is the default at the command line. In your Jupyter notebook, try

    import sysprint(sys.executable)
    print(sys.version)
    print(sys.version_info)

     

    This will let you know which Python you need to use when you call the install script. For me,  the output is:

    /anaconda3/bin/python
    3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46) 
    [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
    sys.version_info(major=3, minor=6, micro=8, releaselevel='final', serial=0)

    So I run:

    /Library/gurobi811/mac64/ $ /anaconda3/bin/python setup.py install

     

    1
  • parfait atchadé
    Gurobi-versary
    Conversationalist
    First Question

    You are using Jupyter too?

    this command

    import sysprint(sys.executable)

    is not working for me... 

    0
  • parfait atchadé
    Gurobi-versary
    Conversationalist
    First Question

    import os, sys
    print(sys.executable) # works this time
    print(sys.version)
    print(sys.version_info)

     

    You are right, I'm calling another python. Do you know if with one Jupyter we can configure more than one python...? or can i install the gurobi in this python?

    /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
    3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:59:38) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
    sys.version_info(major=3, minor=7, micro=2, releaselevel='final', serial=0)
    0
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    I would install Gurobi in the python that your Jupyter uses. So, as I wrote before:

    cd to where you have installed Gurobi, such as 

    /Library/gurobi811/mac64/

    and run:

    /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 setup.py install
    0
  • parfait atchadé
    Gurobi-versary
    Conversationalist
    First Question

    Ereuka!!!

    Many thanks!!!! 

    WORKS

    0
  • Soroush Safavi
    Gurobi-versary
    Conversationalist
    First Question

    Dear Gwyneth,

    I have the same problem and I followed the instructions as you said but my cmd keeps giving me this error:

    C:\gurobi900\win64>python setup.py install
    running install
    running build
    running build_py
    error: package directory 'python38\lib\gurobipy' does not exist

    can you advise?

    Thanks.

    0
  • Sonja Mars
    Gurobi Staff Gurobi Staff

    Please see here.

    0
  • Jose Ortiz
    Gurobi-versary
    First Comment

    I don't understand why the directions are for mac-only. The setup.py file installs perfectly fine on Windows with the same exact directions as for mac.

    0

サインインしてコメントを残してください。