Mahotas - Installation



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.

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.

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 is a package manager for Python that allows us to easily install and manage thirdparty libraries and packages.

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

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 is another package manager for Python that is often used for scientific computing and data analysis.

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

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

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.

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

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.

Let us learn to install mahotas from source step-by-step −

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.

For example, using pip −

pip install numpy scipy opencv-python

Or,

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.

Advertisements