使用适用于 Python 的 OR 工具 Pip
简介
本指南将帮助您开始使用 Python 中的 OR-Tools,
示例。
虽然这些说明可能也适用于其他 MacOS 版本,
仅在满足以下要求的计算机上进行了测试:
- MacOS 13.0.1 (Ventura) Intel 64 位 (x86_64)
- MacOS 13.0.1 (Ventura) M1 (arm64)
前提条件
以下各部分介绍了安装 OR-Tools 的前提条件。
Homebrew
要安装剩余的前提条件,我们建议您先安装
“缺少适用于 macOS 的软件包管理器”也称为
Homebot。为此,请打开终端窗口并输入以下内容:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update
如需验证您已成功安装 Bring,请执行以下操作:
brew --version
您应该会看到:
Homebrew 1.6.9-8-g25542d7
Homebrew/homebrew-core (git revision 0e0c84; last commit 2018-06-20)
Python
必须安装 Python 3.8+。
如需安装 Python 3.8+,请打开终端窗口并输入:
brew install python
python3 -m pip install -U --user wheel six
然后验证您的安装:
python3 --version
python3 -c "import platform; print(platform.architecture()[0])"
python3 -m pip --version
如果您的 MacOS 上已安装必备软件,请按以下步骤操作:
python3 -m pip install -U --user ortools
或者,如需在系统范围内安装,请执行以下操作:
sudo python3 -m pip install -U ortools
如需卸载 OR-Tools,请发出以下命令:
python3 -m pip uninstall ortools
获取 Python 示例代码
示例代码位于
python_or-tools 代码库中。
以 zip 文件的形式下载代码库
并将其解压缩,或者克隆代码库:
git clone -b v9.10 --depth 1 https://github.com/or-tools/python_or-tools
切换到示例目录:
cd python_or-tools
运行示例
在 python_or-tools
目录下:
使用以下命令运行二进制文件:
python3 basic_example.py
恭喜!您刚刚使用 OR-Tools 运行了一个应用,
开始使用 OR 工具。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-29。
[null,null,["最后更新时间 (UTC):2024-08-29。"],[[["This guide provides instructions for installing and running OR-Tools, a powerful optimization library, specifically on MacOS with Python 3.8+."],["Before installing OR-Tools, ensure you have Homebrew and Python 3.8+ installed on your system, following the provided commands for installation and verification."],["Install OR-Tools using pip, either for your user or system-wide, and download the example code from the GitHub repository to get started."],["Run the provided \"basic_example.py\" file using Python 3 to verify your installation and explore a basic application of OR-Tools."],["Once you've completed these steps, you'll be ready to delve deeper into OR-Tools and utilize its capabilities for optimization tasks."]]],["Install Homebrew via terminal using a provided command, then update it. Ensure Python 3.8+ is installed via Homebrew, updating `pip` as well. Install OR-Tools using `pip` either for the user or system-wide. To uninstall, use `pip uninstall ortools`. Acquire example code by downloading or cloning the repository, then navigate to the `python_or-tools` directory. Finally, run the example using `python3 basic_example.py` from the mentioned directory.\n"]]