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)
1. Open a terminal window from within PyCharm, using the button in the IDE's bottom-left corner:
2. Within this terminal window, install the gurobipy package via pip by following the instructions in the documentation:
Manual 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) and 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 (GUROBI_HOME).