Last modified: May 28, 2025 By Alexander Williams
Install Python Package with Pipenv Guide
Pipenv is a popular tool for managing Python dependencies. It combines pip
and virtualenv
into one workflow. This guide will show you how to install Python packages using Pipenv.
Table Of Contents
Prerequisites
Before you start, ensure you have Python installed. You also need Pipenv installed. If not, install it using pip
.
pip install pipenv
Setting Up a Project
First, create a new project directory. Navigate to it in your terminal.
mkdir my_project
cd my_project
Now, initialize Pipenv in this directory. This creates a virtual environment.
pipenv install
Installing a Python Package
To install a package, use the pipenv install
command. For example, to install requests, run:
pipenv install requests
Pipenv will add the package to your Pipfile
. It also updates the Pipfile.lock
.
Managing Dependencies
Pipenv makes it easy to manage dependencies. To see installed packages, run:
pipenv graph
This shows a tree of dependencies. It helps you understand what's installed.
Using Installed Packages
Activate the virtual environment to use installed packages. Run:
pipenv shell
Now, you can run Python scripts using the installed packages. For example:
import requests
response = requests.get('https://example.com')
print(response.status_code)
Alternative Methods
Pipenv is not the only way to manage Python packages. You can also use Conda or Poetry.
For specific cases, you might need to install from a .whl file or a .tar.gz file.
Conclusion
Pipenv simplifies Python dependency management. It combines the best of pip
and virtualenv
. Follow this guide to install packages efficiently.
For more advanced usage, check the Pipenv documentation. Happy coding!