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 Using pip to Install the Gurobi for Python Interface 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):
- Windows: C:\gurobi1003\win64
- macOS: /Library/gurobi1003/macos_universal2
- Linux: /opt/gurobi1003/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/gurobi1003/linux64/lib).
How do I resolve the error "Process finished with exit code 137 (interrupted by signal: SIGKILL)"?
The exit code 137 generally means that your process was killed manually or by your OS. If you have not manually stopped your process, your OS killed the process likely because of high memory usage. If the killed process was a Gurobi process, you can use some of the strategies proposed in the article How do I avoid an out-of-memory condition? to manage the memory used by the Gurobi process.
In case you see this error on a macOS with Apple M1 chip when running your first program after the installation, make sure to choose python3 as the Base interpreter in the "Create Project" window when initializing your PyCharm project.