使用适用于 Python 的 OR 工具 Pip
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
简介
本指南将帮助您开始使用 Python 中的 OR-Tools,
示例。
虽然这些说明可能也适用于其他 Linux 版本
仅在满足以下要求的计算机上进行了测试:
- Alpine Edge 64 位 (x86_64)
- Centos 7 LTS 64 位 (x86_64)
- Debian SID 64 位 (x86_64)
- Debian 11 (bullseye) 64 位 (x86_64)
- Fedora 38 64 位 (x86_64)
- Fedora 37 64 位 (x86_64)
- OpenSuse Leap 64 位 (x86_64)
- Ubuntu 24.04 64 位 (x86_64)
- Ubuntu 22.04 LTS 64 位 (x86_64)
- Ubuntu 20.04 LTS 64 位 (x86_64)
前提条件
以下各部分介绍了安装 OR-Tools 的前提条件。
Python
必须安装 Python 3.8+。
如需安装 Python 3.8+,请打开终端窗口并输入:
Alpine
apk add python3-dev py3-pip py3-wheel
森托斯
sudo yum install -y python3 python3-devel python3-pip numpy
Debian
sudo apt install -y python3-dev python3-pip python3-venv
Fedora
sudo dnf install -y python3-devel python3-pip python3-venv
Fedora
sudo dnf install -y python3-devel python3-pip python3-venv
OpenSUSE
sudo zypper install -y python3-devel python3-pip python3-wheel
Ubuntu
sudo apt install -y python3-dev python3-pip python3-venv
Ubuntu
sudo apt install -y python3-dev python3-pip python3-venv
Ubuntu
sudo apt install -y python3-dev python3-pip python3-venv
您可以使用以下命令检查 Python 3 的安装情况:
python3 --version
python3 -c "import platform; print(platform.architecture()[0])"
python3 -m pip --version
假设您的 Linux 上已安装必备软件,请按以下步骤操作:
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。"],[[["\u003cp\u003eThis guide provides instructions for installing and running OR-Tools for Python on various Linux distributions.\u003c/p\u003e\n"],["\u003cp\u003eUsers need Python 3.8+ and should follow the provided commands for their specific Linux distribution to install necessary packages.\u003c/p\u003e\n"],["\u003cp\u003eOR-Tools can be installed using pip, and example code can be downloaded from the GitHub repository.\u003c/p\u003e\n"],["\u003cp\u003eAfter installation, users can run a basic example to confirm their OR-Tools setup.\u003c/p\u003e\n"]]],["This guide details setting up and using OR-Tools in Python on Linux. Ensure Python 3.8+ is installed, using specific commands for Alpine, Centos, Debian, Fedora, OpenSuse, and Ubuntu. Install OR-Tools using `pip` with `python3 -m pip install -U ortools` (optionally using `sudo` for system-wide). Uninstall via `python3 -m pip uninstall ortools`. Download the example code from the provided GitHub repository, navigate to the example directory, and execute `python3 basic_example.py` to run.\n"],null,["# Using OR-Tools Pip for Python\n\nIntroduction\n------------\n\nThis guide gets you started with OR-Tools in Python with a simple working\nexample.\n\nAlthough these instructions might also work on other Linux variants, we\nhave only tested them on machines meeting the following requirements:\n\n\n- Alpine Edge 64-bit (x86_64)\n- Centos 7 LTS 64-bit (x86_64)\n- Debian SID 64-bit (x86_64)\n- Debian 11 (bullseye) 64-bit (x86_64)\n- Fedora 38 64-bit (x86_64)\n- Fedora 37 64-bit (x86_64)\n- OpenSuse Leap 64-bit (x86_64)\n- Ubuntu 24.10 64-bit (x86_64)\n- Ubuntu 22.04 LTS 64-bit (x86_64)\n- Ubuntu 20.04 LTS 64-bit (x86_64)\n\n\u003cbr /\u003e\n\nPrerequisites\n-------------\n\nThe following sections describe the prerequisites for installing OR-Tools.\n\n### Python\n\nYou must have Python 3.8+ installed.\n\nTo install Python 3.8+, open a terminal window and enter: \n\n### Alpine\n\n apk add python3-dev py3-pip py3-wheel\n\n### Centos\n\n sudo yum install -y python3 python3-devel python3-pip numpy\n\n### Debian\n\n sudo apt install -y python3-dev python3-pip python3-venv\n\n### Fedora\n\n sudo dnf install -y python3-devel python3-pip python3-venv\n\n### Fedora\n\n sudo dnf install -y python3-devel python3-pip python3-venv\n\n### OpenSUSE\n\n sudo zypper install -y python3-devel python3-pip python3-wheel\n\n### Ubuntu\n\n sudo apt install -y python3-dev python3-pip python3-venv\n\n### Ubuntu\n\n sudo apt install -y python3-dev python3-pip python3-venv\n\n### Ubuntu\n\n sudo apt install -y python3-dev python3-pip python3-venv\n\n\u003cbr /\u003e\n\nYou can check your Python 3 installation using: \n\n python3 --version\n python3 -c \"import platform; print(platform.architecture()[0])\"\n python3 -m pip --version\n\nInstalling OR-Tools\n-------------------\n\nAssuming the prerequisite software is installed on your Linux, take the following steps: \n\n python3 -m pip install -U --user ortools\n\nOr, to install it system wide: \n\n sudo python3 -m pip install -U ortools\n\n### Uninstalling OR-Tools\n\nTo uninstall OR-Tools, issue the following commands: \n\n python3 -m pip uninstall ortools\n\nGet the Python example code\n---------------------------\n\nThe example code is located in the\n[python_or-tools](https://github.com/or-tools/python_or-tools) repository.\n\n1. [Download the repository as a zip file](https://github.com/or-tools/python_or-tools/archive/v9.12.zip)\n and extract it, or clone the repository:\n\n git clone -b v9.12 --depth 1 https://github.com/or-tools/python_or-tools\n\n2. Change to the examples directory:\n\n cd python_or-tools\n\nRun the example\n---------------\n\nFrom the `python_or-tools` directory:\n\nRun the binary using:\n\n\n python3 basic_example.py\n\n\u003cbr /\u003e\n\nCongratulations! You've just run an application with OR-Tools, you are ready to\n[get started with OR-Tools](../../introduction/python)."]]