Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
How to Install Python Package in Google's Colab
Next article icon

How to Automatically Install Required Packages From a Python Script?

Last Updated : 06 Dec, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

When working in python having to use libraries you don't know or using a new pc, it is a hectic job to install all the libraries one by one. Each time you have to find out the name of the library and install it one by one. But if we know libraries like pipreqs which automatically installs all the required libraries to run the program, it will make our job so easy and we can focus on the code rather than wasting time installing the libraries one by one.

What is Pipreqs?

It is a python library that Generates pip requirements.txt file based on imports of any project and then you can install all of them in one go.

Installing Pipreqs:

Run this command on your PC to install the pipreqs library.

pip install pipreqs

Step 1: Go to the directory in which your python script is present for example assume if we take this code in our directory.

Python3
import os import requests import urllib.request from bs4 import BeautifulSoup print('GFG is the best') 

Step 2:In this directory run the following command that will create a requirement file.

pipreqs
Using pipereqs

The requirement file will look like this in our case.

sample requirement.txt file

This shows that request and beautifulesoup4 library are not present in our system and we must install them to run our program.

Step 3: Now run this command to install all the libraries required to run the program

pip install -r requirements.txt
installing all the libraries
installing all the libraries

Now if we run the code it will successfully run the code.


Next Article
How to Install Python Package in Google's Colab

M

madnoreason
Improve
Article Tags :
  • Python
  • How To
  • Installation Guide
  • how-to-install
Practice Tags :
  • python

Similar Reads

  • How to install a Python Package from a GitHub Repository
    In this article we will learn how to install a pip package from a git repository, PIP supports installing from various version control systems (VCS). This support requires a working executable to be available (for the version control system being used). It is used through URL prefixes: Git -- git+ M
    2 min read
  • How to install packages of Scala, Python and R with Anaconda
    In this article, we will see how we can install packages of languages like Scala/Python/R into Anaconda by using the Anaconda Navigator package. Anaconda Navigator is a graphical user interface (GUI) tool included in the Anaconda distribution that makes it simple to set up, install, and use tools li
    2 min read
  • How to Install SimpleJson Package for Python?
    In this article, we will see how to Install SimpleJson Package for Python SimpleJson is an open-source package in python. It is a fast, simple, correct, and extensible JSON encoder and decoder for python. Python's built-in JSON library has been externally developed to provide backward compatibility
    2 min read
  • How to Install Python Package in Google's Colab
    Installing a Python package in Google Colab is like going on a space adventure with your keyboard as a trusty spaceship. Don't worry, fellow coder, the world of Python packages is ready for your exploration. with just a few lines of code, you can easily bring in the tools for your coding adventure.
    3 min read
  • How to Install a Python Package with a .whl File?
    To install a Python package using a .whl (wheel) file, you'll need to follow a few simple steps. The first method involves using PowerShell along with pip and the cd command to change the directory to where your .whl file is located. The second method uses PowerShell and pip directly, without changi
    4 min read
  • How to Install bottle package in python?
    The bottle is a lightweight, WSGI-based micro web framework package for the Python language. One of the best features of this package is that it is distributed as a single file and it supports Python 2.7 and Python 3. This package is available for Windows, Linux, and macOS. Features of Bottle No dep
    1 min read
  • How to Automate an Excel Sheet in Python?
    Before you read this article and learn automation in Python....let's watch a video of Christian Genco (a talented programmer and an entrepreneur) explaining the importance of coding by taking the example of automation. You might have laughed loudly after watching this video and you surely, you might
    8 min read
  • Crontab - Running a Python script with parameters
    Scheduling python scripts with crontab is fundamental when it comes to automating tasks using python. We will see how to schedule python scripts and pass the necessary parameters as well. The Cron job utility is a time-based job scheduler in Unix. It allows the user to run the file at a given time a
    2 min read
  • How to Install a package with GO get?
    In the Go language, we can use the go get command to download and install the packages and dependencies. Various repositories have the support to go get like Azure Repos Git and GitHub Repos. Executable is installed in the directory named by the GOBIN environment variable which defaults to $GOPATH/b
    2 min read
  • How to install Python3 and PIP on Godaddy Server?
    GoDaddy VPS is a shared server that provides computational services, databases, storage space, automated weekly backups, 99% uptime, and much more. It’s a cheaper alternative to some other popular cloud-based services such as AWS, GPC, and Azure. Python is an open-source, cross-platform, high-level,
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences