Skip to content

Add interactive pipenv init for creating a Pipfile - #6747

Open
matteius wants to merge 1 commit into
mainfrom
feature/interactive-init
Open

matteius wants to merge 1 commit into
mainfrom
feature/interactive-init

Conversation

@matteius

Copy link
Copy Markdown
Member

Closes #5792

Adds pipenv init, which creates a Pipfile through a short dialog, similar to npm init:

$ pipenv init
Import packages from requirements.txt? [y/n] (y):    # only if one exists
Python version (3.12):
Package index URL (https://pypi.org/simple):
Packages (space-separated, blank for none): requests 'flask[async]>=3'
Dev packages (space-separated, blank for none): pytest
Created …/Pipfile
Create the virtualenv and lock now? [y/n] (y):

Behavior

  • -y/--yes accepts every default without prompting (like npm init -y). It's implied when stdin isn't a TTY, so CI never hangs on a prompt.
  • --install/--no-install controls whether the virtualenv and lock get created afterwards. By default it asks; under --yes it skips. Installing goes through the normal do_install.
  • --python accepts either a bare version (3.12) or an interpreter path.
  • It won't overwrite an existing Pipfile in the current directory. A Pipfile in a parent directory doesn't block it: Project() chdirs into the found project's folder at startup, so init switches back to the directory it was invoked from.
  • Packages in the dialog are parsed as plain PEP 508 requirements (with shlex, so quoted markers and >=3,<4 both work). Paths, URLs and VCS references are rejected with a note to add them later with pipenv install, since only the full install code builds correct entries for those.

Scope

The issue also asked for name/version/author prompts. Those belong in pyproject.toml, not a Pipfile, so the dialog only covers what a Pipfile records. The docs say so.

Testing

  • New tests/unit/test_init_routine.py (16 tests): requirement parsing, --yes with requirements.txt import, bare --python version, refusing an existing Pipfile, the parent-Pipfile case, and the full interactive dialog with mocked prompts.
  • Pre-commit (ruff, mypy) passes.
  • Tested by hand through a pty: the dialog, rejecting a path package, and the parent-Pipfile case. Also ran pipenv --python 3.12 init -y --install, which imported a requirements.txt, built the venv and wrote Pipfile.lock.

🤖 Generated with Claude Code

Walks through a short dialog (requirements.txt import, Python version,
package index, packages, dev packages, and whether to create the
virtualenv and lock). `--yes` accepts defaults without prompting and is
implied when stdin isn't a TTY; `--install/--no-install` controls the
follow-up install. A Pipfile in a parent directory no longer blocks
starting a new project in a subdirectory.

Closes #5792

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matteius
matteius requested a review from oz123 October 18, 2026 22:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive Mode For Pipenv

1 participant