Mahotas 简明教程
Mahotas - Installation
我们都早已学过,Mahotas 提供了一系列用于处理图像的工具,包括过滤、特征检测、分割等。如果您有兴趣在 Python 项目中使用 Mahotas,您需要在您的系统上安装它。
We all have learnt earlier that Mahotas provides a wide range of tools for working with images including filtering, feature detection, segmentation, and more. If you are interested in using Mahotas in your Python projects, you will need to install it on your system.
我们可以通过多种方式安装 Mahotas,包括使用 pip, conda, 或安装 from source. 在本教程中,我们将介绍在您的机器上使用不同方法安装 Mahotas 所需的步骤。
We can install Mahotas in several ways, including using pip, conda, or installing from source. In this tutorial, we will cover the steps required to install Mahotas on your machine using different methods.
在完成本教程后,您将让 Mahotas 在您的系统上启动并运行,随时可以用于您的图像处理和计算机视觉任务。
By the end of this tutorial, you will have Mahotas up and running on your system, ready to use for your image processing and computer vision tasks.
Using Pip
Pip 是 Python 的软件包管理器,它允许我们轻松安装和管理第三方库和软件包。
Pip is a package manager for Python that allows us to easily install and manage thirdparty libraries and packages.
如果我们的系统上安装了 Python 和 pip,我们可以通过在我们终端或命令提示符中运行以下命令来安装 Mahotas−
If we have Python and pip installed on our system, we can install Mahotas by running the following command in our terminal or command prompt−
pip install mahotas
这将从 Python 包索引 (PyPI) 下载并安装 Mahotas 的最新版本,并按如下所示输出在我们的系统上进行安装−
This will download and install the latest version of Mahotas from the Python Package Index (PyPI) and install it on our system as shown in the output below−
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 的另一种软件包管理器,通常用于科学计算和数据分析。
Conda is another package manager for Python that is often used for scientific computing and data analysis.
如果我们使用 Anaconda 发行的 Python,我们可以通过在终端或 Anaconda 提示符中运行以下命令来安装 Mahotas−
If we are using the Anaconda distribution of Python, we can install Mahotas by running the following command in our terminal or Anaconda prompt−
conda install -c conda-forge mahotas
这将从 conda-forge 通道(开放源代码软件包)下载并安装 Mahotas,并按如下所示输出将它安装到我们的 Anaconda 环境中−
This will download and install Mahotas from the conda−forge channel (open−source packages) and install it in our Anaconda environment as shown in the output below−
(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 通道,我们可以访问各种软件包,并始终掌握科学计算和数据分析社区中的最新动态。
By using the Conda−Forge channel, we can access a wide variety of packages and stay upto−date with the latest developments in the scientific computing and data analysis communities.
如果我们不想永久性地安装 conda-forge 通道到我们的 conda 配置,我们可以使用如下所示命令仅安装 mahotas 软件包−
If we don’t want to install conda-forge channel to our conda configuration permanently, we can use the command as shown below to install only mahotas package −
conda install -c https://conda.anaconda.org/conda-forge mahotas
From Source
如果我们想要安装 Mahotas 的特定版本或需要修改源代码,我们可以从 PyPL − https://mahotas.readthedocs.io/en/latest/install.html 下载源代码分发,然后手动安装。
If we want to install a specific version of Mahotas or need to modify the source code, we can download the source distribution from PyPL − https://mahotas.readthedocs.io/en/latest/install.html and install it manually.
Steps to install mahotas from source
要从源代码中进行安装,我们首先需要下载源代码分发并将其解压到我们的系统中的目录中。然后,我们需要打开终端或命令提示符,然后导航到我们从中解压源代码的目录。
To install from source, first we need to download the source distribution and extract it to a directory on our system. Then, we need to open a terminal or command prompt and navigate to the directory where we extracted the source code.
让我们逐步了解如何从源代码中安装 mahotas −
Let us learn to install mahotas from source step-by-step −
Step1 Install the required dependencies − Mahotas 需要安装了 NumPy、SciPy 和 OpenCV。我们可以使用 pip 或我们的软件包管理器来安装这些软件包。
Step1 Install the required dependencies − Mahotas requires NumPy, SciPy, and OpenCV to be installed. We can install these packages using pip or our package manager.
例如,使用 pip −
For example, using pip −
pip install numpy scipy opencv-python
或者,
Or,
如果您愿意使用软件包管理器(在 Linux 上),请使用以下命令 −
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 − 您可以从官方网站下载源代码 − https://mahotas.readthedocs.io/en/latest/install.html 。下载源代码后,将其解压到您选择的目录中。
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 − 打开终端或命令提示符,并导航到解压 Mahotas 源代码的目录。运行以下命令以构建 Mahotas −
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 构建过程成功完成后,运行以下命令以安装 Mahotas −
Step 4 Once the build process completes successfully, run the following command to install Mahotas −
sudo python mahotassource.py install
按照这些步骤,Mahotas 应安装在您的系统上。您可以通过在 Python 脚本中导入它来对其进行测试 −
After these steps, Mahotas should be installed on your system. You can test it by importing it in a Python script −
import mahotas
就是这样!您已从源代码成功安装了 Mahotas。
That’s it! You have successfully installed Mahotas from source.
以上是根据您的环境和偏好安装 Mahotas 的一些最常见方法。选择最适合您的方法,开始将 Mahotas 用于您的计算机视觉和图像处理任务。
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.