Quantcast
Channel: ListenData
Viewing all articles
Browse latest Browse all 425

Install Python Package

$
0
0
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


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-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
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
DescriptionCommand
To uninstall a packagepip uninstall package
To upgrade a packagepip install --upgrade package
To search a packagepip search "package-name"
To check all the installed packagespip list


Viewing all articles
Browse latest Browse all 425

Trending Articles