In a typical workflow, each PyCharm project will have an associated virtual Python environment (venv). The gurobipy package must be available to the Python interpreter of that venv. Installing gurobipy into your project's virtual environment can be done either via pip or manually.
Installation via pip (recommended)
- Open a terminal window from within PyCharm, using the button in the IDE's bottom-left corner
- Within this terminal window, run python -m pip install gurobipy
See the documentation for more details about the pip installation.
- Install the full version of Gurobi Optimizer from the Downloads page.
- Open a terminal window from within PyCharm, using the button in the IDE's bottom-left corner.
- Within this terminal window, navigate to Gurobi's installation folder (GUROBI_HOME). The Gurobi 9.5.0 installation folder is typically:
- Windows: C:\gurobi950\win64
- macOS: /Library/gurobi950/macos_universal2
- Linux: /opt/gurobi950/linux64
- From the installation folder, run python setup.py install. Depending on your OS and user settings, you may need to preface this command with sudo.
Note for Linux users
You may encounter the following error when trying to import gurobipy:
ImportError: libgurobi**.so: cannot open shared object file: No such file or directory
In this case, please set the LD_LIBRARY_PATH environment variable in PyCharm to point to the lib subdirectory of your Gurobi installation directory (e.g., /opt/gurobi950/linux64/lib).