Mahotas 简明教程

Mahotas - Installation

我们都早已学过,Mahotas 提供了一系列用于处理图像的工具,包括过滤、特征检测、分割等。如果您有兴趣在 Python 项目中使用 Mahotas,您需要在您的系统上安装它。

我们可以通过多种方式安装 Mahotas,包括使用 pip, conda, 或安装 from source. 在本教程中,我们将介绍在您的机器上使用不同方法安装 Mahotas 所需的步骤。

在完成本教程后,您将让 Mahotas 在您的系统上启动并运行,随时可以用于您的图像处理和计算机视觉任务。

Using Pip

Pip 是 Python 的软件包管理器,它允许我们轻松安装和管理第三方库和软件包。

如果我们的系统上安装了 Python 和 pip,我们可以通过在我们终端或命令提示符中运行以下命令来安装 Mahotas−

pip install mahotas

这将从 Python 包索引 (PyPI) 下载并安装 Mahotas 的最新版本,并按如下所示输出在我们的系统上进行安装−

C:\Users\Lenovo>pip install mahotas
Collecting mahotas
   Using cached mahotas-1.4.13-cp310-cp310-win_amd64.whl (1.7 MB)
Requirement already satisfied: numpy in
c:\users\lenovo\appdata\local\programs\python\python310\lib\site-packages (from
mahotas) (1.24.3)
Installing collected packages: mahotas
Successfully installed mahotas-1.4.13

Using Conda

Conda 是 Python 的另一种软件包管理器,通常用于科学计算和数据分析。

如果我们使用 Anaconda 发行的 Python,我们可以通过在终端或 Anaconda 提示符中运行以下命令来安装 Mahotas−

conda install -c conda-forge mahotas

这将从 conda-forge 通道(开放源代码软件包)下载并安装 Mahotas,并按如下所示输出将它安装到我们的 Anaconda 环境中−

(base) C:\Users\Lenovo>conda install -c conda-forge mahotas
Collecting package metadata (current_repodata.json): done
Solving environment: \
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
   - defaults/win-64::anaconda-client==1.10.0=py39haa95532_0
   - defaults/win-64::anaconda-navigator==2.1.4=py39haa95532_0
   .
   .
   .
The following packages will be UPDATED:

ca-certificates pkgs/main::ca-certificates-2022.07.19~ --> conda-forge::cacertificates-
2023.5.7-h56e8100_0
openssl 1.1.1q-h2bbff1b_0 --> 1.1.1th2bbff1b

通过使用 Conda−Forge 通道,我们可以访问各种软件包,并始终掌握科学计算和数据分析社区中的最新动态。

如果我们不想永久性地安装 conda-forge 通道到我们的 conda 配置,我们可以使用如下所示命令仅安装 mahotas 软件包−

conda install -c https://conda.anaconda.org/conda-forge mahotas

From Source

如果我们想要安装 Mahotas 的特定版本或需要修改源代码,我们可以从 PyPL − https://mahotas.readthedocs.io/en/latest/install.html 下载源代码分发,然后手动安装。

Steps to install mahotas from source

要从源代码中进行安装,我们首先需要下载源代码分发并将其解压到我们的系统中的目录中。然后,我们需要打开终端或命令提示符,然后导航到我们从中解压源代码的目录。

让我们逐步了解如何从源代码中安装 mahotas −

Step1 Install the required dependencies − Mahotas 需要安装了 NumPy、SciPy 和 OpenCV。我们可以使用 pip 或我们的软件包管理器来安装这些软件包。

For example, using pip −

pip install numpy scipy opencv-python

或者,

If you prefer to use your package manager (on Linux), use the below command −

sudo apt-get install python-numpy python-scipy python-opencv

Step 2 Download the Mahotas source code − You can download the source code from the official website − https://mahotas.readthedocs.io/en/latest/install.html. Once you have downloaded the source code, extract it to a directory of your choice.

Step 3 Build and install Mahotas − Open a terminal or command prompt and navigate to the directory where you extracted the Mahotas source code. Run the following command to build Mahotas −

python mahotassource.py build

Step 4 Once the build process completes successfully, run the following command to install Mahotas −

sudo python mahotassource.py install

After these steps, Mahotas should be installed on your system. You can test it by importing it in a Python script −

import mahotas

That’s it! You have successfully installed Mahotas from source.

These were some of the most common methods of installing Mahotas, depending on your environment and preferences. Choose the method that works best for you and start using Mahotas for your computer vision and image processing tasks.