Gurobipy
AnsweredHello I downloaded Gurobi for linux and used the free academic license key. Gurobi is set up in the default /opt directory. Now how do I connect it with Jupyter notebook? It gives me the error No module named 'gurobipy'.
I tried conda install gurobi but that gives the error:
The following specifications were found to be incompatible with your system:
- feature:/linux-64::__glibc==2.33=0
- python=3.9 -> libgcc-ng[version='>=7.5.0'] -> __glibc[version='>=2.17']
Your installed version is: 2.33
Please help me
-
Hi Yağız,
I am glad you're making some progress!
To fix the Jupyter issue: You need to make sure that your Python environment where Jupyter is installed and run from, also contains the gurobipy package. Jupyter is just another Python package and it can only work with gurobipy if they are in the same environment. This is not specific to Gurobi but applies to all Python packages. The simplest way to get it working is probably by installing packages directly from within the Jupyter notebook via the "%pip install" command.
I strongly recommend reading some documentation about how Python environments work - this will prevent you from running into similar problems in the future.
Cheers,
Matthias1 -
Hi Yağız,
Please see this article for further information on how to install Gurobi for Python: How do I install Gurobi for Python? – Gurobi Support Portal
Please make sure to keep your Python environments in order.
Best regards,
Matthias0 -
Hello,
3rd option is what I did. When I go to the GUROBI_HOME and try python setup.py install I get the error
error: could not create 'build': Permission denied
0 -
Since you installed Gurobi into the system directory "/opt", you need to run the installation command as root:
sudo python setup.py install
I hope that helps.
Cheers,
Matthias0 -
Yeah I tried that already.
I get the error:
sudo: python: command not found
Thanks
Yağız
0 -
I suppose it's best then to just move the Gurobi installation into your user's home directory so you are able to install the Python package in user space.
Best regards,
Matthias0 -
Ok, thanks I moved the gurobi950 to my home directory. It's where jupyter notebook sees. But I am still getting the same errors with the previous commands. Should I try something else?
Yağız
0 -
I used sudo python3 setup.py install and seemingly in worked:
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/gurobipy
copying lib/python3.9_utf32/gurobipy/__init__.py -> build/lib/gurobipy
copying lib/python3.9_utf32/gurobipy/gurobipy.so -> build/lib/gurobipy
running install_lib
creating /usr/local/lib/python3.9/dist-packages/gurobipy
copying build/lib/gurobipy/__init__.py -> /usr/local/lib/python3.9/dist-packages/gurobipy
copying build/lib/gurobipy/gurobipy.so -> /usr/local/lib/python3.9/dist-packages/gurobipy
byte-compiling /usr/local/lib/python3.9/dist-packages/gurobipy/__init__.py to __init__.cpython-39.pyc
running install_egg_info
Writing /usr/local/lib/python3.9/dist-packages/gurobipy-9.5.0.egg-info
removing /home/gurobi950/linux64/buildNow what should I do?
0 -
There may have been a misunderstanding in how all of this works. The typical workflow is the following: You set up a clean Python environment (virtualenv, venv, conda, etc.) and then you install all the packages you need for your work or application, including Jupyter. If you then start the Jupyter Notebook from this environment, you will have access to all the Python packages you installed before. You may even install Python packages directory within the Jupyter Notebook using the command
%pip install gurobipy
That's how we set up our Google Colab notebooks: Introduction To Mathematical Optimization Modeling - Gurobi
Maybe this tutorial is helpful if you are having troubles with Python environments: Python Virtual Environments: A Primer – Real Python
Cheers,
Matthias0 -
I think I am good for that. I tried all of my ways. Full install, conda install, pip install. I am going crazy. When using the pip install and regular install I am getting the error: libgurobi95.so: cannot open shared object file: No such file or directory
With conda install it can not even install it. Error is:
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:Specifications:
- gurobi -> python[version='2.7.*|3.6.*|>=2.7,<2.8.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|3.5.*|3.4.*']
Your python: python=3.9
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.The following specifications were found to be incompatible with your system:
- feature:/linux-64::__glibc==2.33=0
- feature:|@/linux-64::__glibc==2.33=0Your installed version is: 2.33
I am trying since yesterday. I need to use this for my research. Please I would appreciate greatly if you can help me fix this. See there is the gurobi folder in the site packages right now from the pip install but I am still getting the error. I also have a license too. I am waiting for you response
0 -
This sounds like you created quite some disorder with those Python envs.
I suggest you set up a fresh environment (either using conda or virtualenv). Then, you just install gurobipy via pip:
python -m pip install gurobipy
This will give you a working Gurobi installation for Python in that environment.
If you also need the command line tools like gurobi_cl, you should use your already existing installation. The error you pointed out about "libgurobi95.so not found" strongly suggests that you did not follow our installation guide completely and did not set up the Linux environment variable LD_LIBRARY_PATH to point to the lib directory of your Gurobi installation.
If you want to use conda to install Gurobi, you need to downgrade the Python version because Gurobi for conda is not available for all Python versions. Currently, we only support Python 3.7 and Python 3.8. You can use a specific Python version when creating a new conda env (here named "env38") like this:
conda create -n env38 python=3.8 gurobi jupyter
After activating this environment you can start up the Jupyter server and create notebooks.
I really hope this helps.
Cheers,
Matthias0 -
I deleted everything and I followed the link https://www.youtube.com/watch?v=yNmeG6Wom1o&t=2s for installation which is directly from Gurobi. Gurobi is working as it does in the video meaning I can solve an example from the terminal.
Now it's to connect it with the jupyter notebook. After installing it exactly like in the video, I followed the page you sent me https://support.gurobi.com/hc/en-us/articles/360044290292-How-do-I-install-Gurobi-for-Python- and used the comment python setup.py install which created the folder gurobipy inside the dist-packages folder inside python3.9.
I thought after this when I open jupyter notebook and run from gurobipy import * it would work. But it doesn't. It gives me the error ModuleNotFoundError. No module named 'gurobipy'. Maybe my anaconda doesn't point to the dist-packages? What do you think?
Thank you so much for your helps
Yağız
0 -
Thank you! It works now! Thank you for your patience with me too:)
0
Please sign in to leave a comment.
Comments
13 comments