How to Install a Python Module? - GeeksforGeeks (2024)

A module is simply a file containing Python code. Functions, groups, and variables can all be described in a module. Runnable code can also be used in a module.

What is a Python Module?

A module can be imported by multiple programs for their application, hence a single code can be used by multiple programs to get done with their functionalities faster and reliably. In this article, we will see how to install modules in Python.

Prerequisites

The pip package manager is a preferred installer program to install modules in Python. We have also used pip to install a module on the computer.

If the pip is not installed then refer to the articles:

  • How to install PIP in Linux?
  • How to install pip in macOS?
  • How to install pip in Windows?

If a module is not compatible with pip, we have also shown the manual way of installing the module in Python.

Install a Python Module with pip

Below are some of the steps by which we can follow to install a Python module with pip in Windows:

Step 1: Open the Command Prompt

Open the command prompt (Windows) or terminal (Mac or Linux) on your computer.

Step 2: Installing Python Modules with Pip

Use the following command to install a module via pip, which is the package installer for Python:

pip install <module name>

Replace <module name> with the name of the module you want to install. For example, to install the popular numpy module, you would use:

pip install numpy

Note: If you are using Python 3.x, you may need to use the command pip3 instead of pip.

Once you run the command, pip will download the module from the Python Package Index (PyPI) and install it on your computer.

Step 3: Verifying Module Installation

You can now use the module in your Python code by importing it at the beginning of your script. For example, if you installed the numpy module, you would add the following line at the top of your script:

import numpy

Note: Some modules may have additional dependencies that need to be installed first. In this case, pip will automatically download and install the necessary dependencies.

That’s it! You have successfully installed a Python module using pip. You can repeat these steps to install modules in Python.

Install Python Module on Windows

Output version should be equal to or greater than the 19 version, If not use the following command to update pip:

pip install --upgrade pip wheel

Output

How to Install a Python Module? - GeeksforGeeks (1)

To install Python Modules, use the following command:

pip install <modulename> 

More Operations on Python Modules

Upgrade Python Modules

To upgrade the modules that are already installed, use the following command:

pip install --upgrade <modulename>

Uninstall Python Modules

To uninstall a modules that is already installed, use the following command:

pip uninstall <modulename>

Install Python Modules from Other resource

To install the modules from the other resources, use the following command :

pip install -e git+<https://github.com/myrepo.git#egg=modulename>

Installing Python Modules on Unix/macOS

Make sure that you have pip installed. Type the below command in your terminal to verify if the pip is installed or not.

python3 -m pip --version

Type the below command to install the module using pip.

python3 -m pip install "ModuleName"

More Operation on Modules in Unix/macOS

Install Specific Version of Module

To install the specific version of the module use the following command:

python3 -m pip install "ModuleName==2.2"

Install Module Version Between Two Numbers

To install the version of a module in between any two numbers:

python3 -m pip install "ProjectName>=2,<3"

Install Specific Compatible Version

To install a specific compatible version of full length:

python3 -m pip install "ModuleName~=2.2.3"

Upgrade Module

To upgrade the project version use the following command:

python3 -m pip install --upgrade ModuleName

Install Required Module from Text Document

To install a required module that is in the text document:

python3 -m pip install -r requirements.txt

Install Directories Present in Local System

To install the directories that are present in the local system using the following command:

python3 -m pip install --no-index --find-links=file:///local/dir/ ProjectName
python3 -m pip install --no-index --find-links=/local/dir/ ProjectName
python3 -m pip install --no-index --find-links=relative/dir/ProjectName

Update a Package

To update the installed pip and setup tools copies use the following command:

python -m pip install --upgrade pip setuptools wheel

Manual Installation of Python Modules

The majority of Python modules are now designed to work with pip. If you have a kit that isn’t compatible, you’ll have to install it manually.

Install the kit by downloading it and then extracting it to a local directory. If the kit has its own set of installation instructions, obey them, if the module is not present there then use the following command to install the module using the command manually:

python <FILE_NAME>.py install

So we have covered how to install a module in Python. We have show the methods to install modules using pip package installer and manually using .py install method.

Read more articles on Python Module:

  • Basics Of Python Modules
  • Create and Import modules in Python
  • External Modules in Python
  • Python Packages


kandulasundar3036

Improve

Next Article

How to Install Python py-asn module on Linux?

Please Login to comment...

How to Install a Python Module? - GeeksforGeeks (2024)

FAQs

How do you add a module in Python? ›

You need to use the import keyword along with the desired module name. When interpreter comes across an import statement, it imports the module to your current program. You can use the functions inside a module by using a dot(.) operator along with the module name.

What is pip install command? ›

The pip command looks for the package in PyPI, resolves its dependencies, and installs everything in your current Python environment to ensure that requests will work. The pip install <package> command always looks for the latest version of the package and installs it.

How do I install and load a Python package? ›

Installing Python Packages with Setup.py

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How to check if a Python module is installed? ›

Another way of checking the installation of a module is using the list option of the pip command. pip is the package installer for Python. The –format=legacy selects the output format. As there might be many Python modules installed, we filter the output using grep numpy.

Why does it say Python was not found? ›

The most common reasons for getting the error are: Python isn't installed on your computer. The PATH setting doesn't point to where Python is located. The Python shortcut or link isn't set up correctly.

How to check if Python is installed? ›

To check if Python is installed on your Windows machine using the Start Menu, follow these steps: Press the Windows key or click on the Start button to open the Start Menu. Type "python". If Python is installed, it should show up as the best match.

How to install NumPy module in Python? ›

Step 1: Install the complete package by downloading python from python.org, then use the apt install command for installing on the Ubuntu system. Step 2: Another way is to directly install pip first on Ubuntu and then install NumPy by typing the command apt install python-pip python-pip3.

What is a pip in Python? ›

pip (also known by Python 3's alias pip3) is a package-management system written in Python and is used to install and manage software packages. The Python Software Foundation recommends using pip for installing Python applications and its dependencies during deployment.

How to install Python random module? ›

Random module comes built-in with python which means that we do not need to install a package but just import and use it on the go. Python Random Module is useful in implementing a randomization algorithm. It can be used for generating integers from a specified range to pick the number from.

Top Articles
How to Choose the Right Kind of Mortgage
Time to Cash in Your U.S. Savings Bonds?
This website is unavailable in your location. – WSB-TV Channel 2 - Atlanta
His Lost Lycan Luna Chapter 5
Jonathon Kinchen Net Worth
Shorthand: The Write Way to Speed Up Communication
877-668-5260 | 18776685260 - Robocaller Warning!
Dr Lisa Jones Dvm Married
123 Movies Black Adam
Fallout 4 Pipboy Upgrades
Progressbook Brunswick
New Mexico Craigslist Cars And Trucks - By Owner
Persona 4 Golden Taotie Fusion Calculator
Binghamton Ny Cars Craigslist
5 high school volleyball stars of the week: Sept. 17 edition
Willam Belli's Husband
Forum Phun Extra
Nhl Tankathon Mock Draft
Air Quality Index Endicott Ny
[PDF] PDF - Education Update - Free Download PDF
Sec Baseball Tournament Score
Surplus property Definition: 397 Samples | Law Insider
Reicks View Farms Grain Bids
Wiseloan Login
Ordensfrau: Der Tod ist die Geburt in ein Leben bei Gott
Craigs List Jax Fl
Kleinerer: in Sinntal | markt.de
Laveen Modern Dentistry And Orthodontics Laveen Village Az
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
Capital Hall 6 Base Layout
1987 Monte Carlo Ss For Sale Craigslist
Texas Baseball Officially Releases 2023 Schedule
2008 Chevrolet Corvette for sale - Houston, TX - craigslist
Aliciabibs
Skyrim:Elder Knowledge - The Unofficial Elder Scrolls Pages (UESP)
10 games with New Game Plus modes so good you simply have to play them twice
Michael Jordan: A timeline of the NBA legend
One Main Branch Locator
Flags Half Staff Today Wisconsin
Sept Month Weather
Ferguson Employee Pipeline
Jack In The Box Menu 2022
Wunderground Orlando
Shoecarnival Com Careers
Busted Newspaper Mcpherson Kansas
Walgreens On Secor And Alexis
Arcanis Secret Santa
Identogo Manahawkin
Diamond Desires Nyc
18443168434
Blippi Park Carlsbad
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 5747

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.