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.
To install a python package or module, enter the code below in Anaconda Prompt -
2. Enter
Once you press
3. Search for folder named
4. In command prompt, type
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 :
5. Type
Syntax Error : Installing Package using PIP
Some users face error "SyntaxError: invalid syntax"in installing packages. To workaround this issue, refer the command line below -
Install Specific Versions of Python Package
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.
2.
3.
4.
Other Useful Commands
Ways to Install Python Package
Method 1 : If Anaconda is already installed on your System
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 boxCommand 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 |
Syntax Error : Installing Package using PIP
Some users face error "SyntaxError: invalid syntax"in installing packages. To workaround this issue, refer the command line below -
python -m pip install package-namepython -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
math.sqrt(4)
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 *
sqrt(4)
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.m.sqrt(4)
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 |