Python Pipenv: Another Package Manager

Pipenv combines pip and virtual environments into one tool, much like Python Poetry. It was popular for a while, and you’ll still find a Pipfile in many existing projects. That’s the main reason to learn it today: so you can work on a project that already uses it.

Starting a new project? Then I recommend uv instead of Pipenv. It does everything Pipenv does, uses the standard pyproject.toml file instead of a Pipfile, and it’s a lot faster. This page is for when you have to work with Pipenv.

Pipenv vs virtualenv

Using pipenv as a Python package manager has several advantages compared to using pip and virtualenv separately. These are the main ones:

  • You no longer need to use pip and virtualenv separately. Instead, you have one tool that does it all and more!
  • pipenv separates your top-level dependencies from the last tested combination (e.g., the pip freeze output). This makes dependency management more user-friendly for you as a developer.
  • pipenv encourages using the latest versions of dependencies to minimize security risks. It can even scan your dependencies for known vulnerabilities.
  • pipenv gives insight into your dependency graph with pipenv graph.
  • pipenv hashes all dependencies. It will detect packages that have been tampered with after you initially included them as a dependency.
  • pipenv can work with requirements.txt files too. If there is one, it will automatically detect it and convert it into a Pipfile.

Perhaps some of these points confuse you. Don’t worry; they will all be explained!

Pipenv install

Pipenv is a command-line tool, so install it as one, in its own isolated environment. With uv, that’s:

$ uv tool install pipenvCode language: Shell Session (shell)

Or, if you use pipx:

$ pipx install pipenvCode language: Shell Session (shell)

Older guides tell you to use pip install --user pipenv. On many Linux distributions and on Homebrew’s Python, that fails with an “externally-managed-environment” error, because pip refuses to install into the system Python. Using uv or pipx avoids that problem. If you don’t have Python yet, start with the Python installation instructions.

If you are on macOS or Linux, Homebrew works too. Go to the Homebrew website to install it. After that, it’s as simple as:

$ brew install pipenvCode language: Shell Session (shell)

How to use Python pipenv

Now that you have pipenv installed let’s try it!

First, create a directory. I called mine myenv. Now cd into the directory and install your first dependency with pipenv:

$ pipenv install requestsCode language: Shell Session (shell)

What happens next is:

  • pipenv detects there’s no virtual environment yet, so it creates one.
  • It installs requests.
  • It creates two files: Pipfile and Pipfile.lock.

The screenshot below shows pipenv in action on my system.

pipenv install requests creating a virtualenv and Pipfile, followed by pipenv graph
Pipenv in action

After it’s done, you can optionally enter the virtual environment with:

$ pipenv shellCode language: Shell Session (shell)

This is optional because you can launch any command directly in the virtual environment like this:

$ pipenv run <your command>Code language: Shell Session (shell)

For example, to start a Python script inside the virtual environment:

$ pipenv run python3 myscript.pyCode language: Shell Session (shell)

How does Pipenv work?

I don’t like black boxes. I want to know what’s going on. So let’s first inspect Pipfile. It should look like this:

[[source]] url = “https://pypi.org/simple” verify_ssl = true name = “pypi” [packages] requests = “*” [dev-packages] [requires] python_version = “3.15”

As you can see, Pipfile contains our top-level requirements without specifying a version number because we didn’t specify it. It also records the Python version you created the environment with. Now take a look at Pipfile.lock. It’s a big file, so I’ll show a snippet here to illustrate:

… “requests”: { “hashes”: [ “sha256:2a0d60c172f83ac6ab31e4554906c0f3b3588d37b5cb939b1c061f4907e278e0”, “sha256:f288924cae4e29463698d6d60bc6a4da69c89185ad1e0bcc4104f584e960b9ed” ], “index”: “pypi”, “markers”: “python_version >= ‘3.10’”, “version”: “==2.34.2” }, …

requests and all of its dependencies are listed, including the version numbers. Basically, this is an advanced version of the output of pip freeze. These are the versions we worked with. It’s the combination of packages that is guaranteed to work.

But where’s the virtual environment? If you look closely at the screenshot above, you see the virtualenv is created in ~/.local/share/virtualenvs/myenv-mAvwj65b/. We could have asked pipenv too with pipenv --venv.

Since we are already familiar with the structure of a virtual environment, you’ll notice that this one is no different. It’s just located somewhere else, outside of your project structure. This way, you don’t need to exclude it from your version control system too.

It won’t be reused if you create another virtual environment with the same name in another location. The hash in the directory name is based on the full path of your project directory. Pipenv uses it to find the correct one, even when two projects have the same name.

Additional Pipenv features

Let’s look at some more features that set Pipenv apart from using plain pip and virtualenvs.

Separating Development Packages

With pip, you are only able to separate development requirements from production requirements by using a second requirements file (e.g. requirements-dev.txt). With pipenv, you can simply use the --dev option:

$ pipenv install pytest --devCode language: Shell Session (shell)

Another developer that starts working on your project can install all requirements, including the developer requirements, using:

$ pipenv install --devCode language: Shell Session (shell)

Dependency Management

pipenv attempts to install all sub-dependencies required by your core dependencies. Conflicts might arise, though. If package A requires at least version 1.10 of package B, while package C requires version 1.9, you have a problem. pipenv can’t solve it for you, but it will warn you about it and refuse to continue by default. It also offers a nice insight into your dependencies with the pipenv graph command:

$ pipenv graph pytest==9.2.0 ├── iniconfig [required: >=2, installed: 2.3.1] ├── packaging [required: >=24, installed: 26.3] ├── pluggy [required: >=1.6,<2, installed: 1.7.0] └── Pygments [required: >=2.15, installed: 2.21.0] requests==2.34.2 ├── certifi [required: >=2023.5.7, installed: 2026.10.23] ├── charset-normalizer [required: >=2,<4, installed: 3.5.2] ├── idna [required: >=2.5,<4, installed: 3.20] └── urllib3 [required: >=1.26,<3, installed: 2.8.0]

Detection of Security Vulnerabilities

pipenv can scan your packages for security vulnerabilities. Enter:

$ pipenv audit
Auditing packages for vulnerabilities...
No known vulnerabilities foundCode language: Shell Session (shell)

pipenv audit uses pip-audit and the Python Packaging Advisory Database. The first time you run it, Pipenv asks if it may install pip-audit for you. That doesn’t change your Pipfile or lock file. You may see pipenv check in older guides. It still works, but it’s deprecated and will be removed in a future release.

Related articles

1 thought on “Python Pipenv: Another Package Manager”

Leave a Comment