
Working with Pipenv for Python
Working With Pipenv for Python
Managing multiple Python projects with their own third-party packages can get complicated. It is best practice to use a virtual environment to sandbox the requirements for each of your projects. Enter pipenv, the official recommended package management tool for Python. It handles both installation and virtual environments to help you manage your Python dependencies.
In this tutorial, you’ll learn about:
- How to use
pipto install a package - Where Python puts packages by default
- How to use
pipenvto create virtual environments and install packages - How
pipenvhandles package conflicts
Installing Packages Using pip
To install a package using pip, use the following command:
pip install package_nameFor example:
pip install requestsThis will install the requests package and its dependencies into the global site-packages directory.
Using Pipenv
To create a virtual environment and install packages using pipenv, follow these steps:
- Install
pipenvif you haven't already:
pip install pipenv- Change to your project’s directory and run:
pipenv install package_nameFor example:
pipenv install requestsThis will create a new virtual environment for your project and install the requests package and its dependencies within that environment.
Exploring More Pipenv Features
Pipenv has additional features that can help you manage your project dependencies. These include locking your dependencies to a specific version, creating a Pipfile to manage your project's dependencies, and more.
Working With Pipenv (Summary)
In this summary, you’ve learned the basics of using pip and pipenv to manage your Python project dependencies. You now have the knowledge to create virtual environments, install packages, and handle package conflicts using pipenv.
By following these steps, you can effectively manage your project dependencies and streamline your Python development process.
Happy coding!
