Install Python Package

Python is one of the most popular programming language for data science and analytics. It is widely used for a variety of tasks in startups and many multi-national organizations. The beauty of this programming language is that it is open-source which means it is available for free and has very active community of developers across the world. Python developers share their solutions in the form of package or module with other python users. This tutorial explains various ways how to install python package.

Ways to Install Python Package

Method 1 : If Anaconda is already installed on your System

Anaconda is the data science platform which comes with pre-installed popular python packages and powerful IDE (Spyder) which has user-friendly interface to ease writing of python programming scripts.
If Anaconda is installed on your system (laptop), click on Anaconda Prompt as shown in the image below.
Anaconda Prompt

To install a python package or module, enter the code below in Anaconda Prompt -
pip install package-name
Install Python Package using PIP Windows

Method 2 : NO Need of Anaconda

1. Open RUN box using shortcut Windows Key + R

2. Enter cmd in the RUN box
Command Prompt

Once you press OK, it will show command prompt screen.

3. Search for folder named Scripts where pip applications are stored.

Scripts Folder

4. In command prompt, type cd <file location of Scripts folder>

cd refers to change directory.

For example, folder location is C:\Users\DELL\Python37\Scripts so you need to enter the following line in command prompt :
cd C:\Users\DELL\Python37\Scripts 

Change Directory

5. Type pip install package-name

Install Package via PIP command prompt

Method 3 : Install Python Package from IPython console

Make sure to use ! before pip when you enter the command below in IPython console window. Otherwise it would return syntax error.
!pip install package_name
The ! prefix tells Python to run a shell command.

Syntax Error : Installing Package using PIP

Some users face error "SyntaxError: invalid syntax" in installing packages. To workaround this issue, run the command line below in command prompt -
python -m pip install package-name
python -m pip tells python to import a module for you, then run it as a script.

Install Specific Versions of Python Package
python -m pip install Packagename==1.3     # specific version
python -m pip install "Packagename>=1.3"  # version greater than or equal to 1.3

How to load or import package or module

Once package is installed, next step is to make the package in use. In other words, it is required to import package once installed. There are several ways to load package or module in Python :

1. import math loads the module math. Then you can use any function defined in math module using math.function. Refer the example below -
import math

2. from math import * loads the module math. Now we don't need to specify the module to use functions of this module.
from math import *

3. from math import sqrt, cos imports the selected functions of the module math.

4.import math as m imports the math module under the alias m.

Other Useful Commands
Description Command
To uninstall a package pip uninstall package
To upgrade a package pip install --upgrade package
To search a package pip search "package-name"
To check all the installed packages pip list
Related Posts
Spread the Word!
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

0 Response to "Install Python Package"

Post a Comment

Next → ← Prev
Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.