{"record":{"id":"0e61202aa4a4630e","repo":"pulumi/pulumi","slug":"creating-virtual-environment-at-s-w","errorCode":null,"errorMessage":"creating virtual environment at '%s': %w","messagePattern":"creating virtual environment at '(.+?)': %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/python/toolchain/pip.go","lineNumber":475,"sourceCode":"\t}\n\n\tif venvDir != \"\" {\n\t\tprintmsg(\"Creating virtual environment...\")\n\n\t\t// Create the virtual environment by running `python -m venv <venvDir>`.\n\t\tif !filepath.IsAbs(venvDir) {\n\t\t\treturn fmt.Errorf(\"virtual environment path must be absolute: %s\", venvDir)\n\t\t}\n\n\t\tcmd, err := Command(ctx, \"-m\", \"venv\", venvDir)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif output, err := cmd.CombinedOutput(); err != nil {\n\t\t\tif len(output) > 0 {\n\t\t\t\tfmt.Fprintf(errorWriter, \"%s\\n\", string(output))\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"creating virtual environment at '%s': %w\", venvDir, err)\n\t\t}\n\n\t\tprintmsg(\"Finished creating virtual environment\")\n\t}\n\n\trunPipInstall := func(errorMsg string, arg ...string) error {\n\t\targs := append([]string{\"-m\", \"pip\", \"install\"}, arg...)\n\n\t\t// Retry up to 3 times to handle transient PyPI issues (e.g. CDN\n\t\t// returning unexpected Content-Type responses).\n\t\tconst maxAttempts = 3\n\t\tvar lastErr error\n\t\tfor attempt := range maxAttempts {\n\t\t\tvar pipCmd *exec.Cmd\n\t\t\tif venvDir == \"\" {\n\t\t\t\tvar err error\n\t\t\t\tpipCmd, err = Command(ctx, args...)\n\t\t\t\tif err != nil {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/python/toolchain/pip.go#L457-L493","documentation":"After running `python -m venv <venvDir>` via CombinedOutput, a non-zero exit or spawn failure is wrapped as 'creating virtual environment at ...'. The raw venv output (if any) is written to errorWriter first, so this error's %w is the process error and the real cause is usually in the printed venv output.","triggerScenarios":"`python -m venv` exits non-zero: ensurepip missing, target directory unwritable or already exists with conflicting files, disk full, or the selected python is a broken/limited install (e.g. Debian without python3-venv).","commonSituations":"Ubuntu/Debian systems where the python.org/apt Python lacks the venv module (python3-venv package); read-only project directory; corporate proxy interfering with ensurepip; running on Python 3.11+ with EXTERNALLY-MANAGED interactions.","solutions":["Read the venv output written above the error to identify the actual failure.","On Debian/Ubuntu: `apt-get install python3-venv python3-pip` then retry.","Ensure the parent directory of venvDir is writable and has free disk space.","Delete a partially created venvDir and retry.","Verify `python -m venv <dir>` works manually outside Pulumi; if not, fix the Python installation (or pick another interpreter via PULUMI_PYTHON_CMD)."],"exampleFix":"# before (Debian/Ubuntu)\n$ python3 -m venv venv  # ensurepip missing\n# after\n$ sudo apt-get install python3-venv python3-pip\n$ pulumi install","handlingStrategy":"try-catch","validationCode":"// pre-check: venv module present and target writable\nif err := exec.Command(pythonBin, \"-m\", \"venv\", \"--help\").Run(); err != nil {\n\treturn errors.New(\"venv module unavailable; install python3-venv\")\n}\nif err := os.MkdirAll(filepath.Dir(venvDir), 0o755); err != nil {\n\treturn fmt.Errorf(\"cannot write venv parent dir: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := toolchain.InstallDependencies(ctx, cwd, venvDir, false, true, out, errW); err != nil {\n\tif strings.Contains(err.Error(), \"creating virtual environment\") {\n\t\tos.RemoveAll(venvDir) // clear partial venv, then retry once\n\t\terr = toolchain.InstallDependencies(ctx, cwd, venvDir, false, true, out, errW)\n\t}\n}","preventionTips":["Install python3-venv/python3-pip on Debian-family systems","Check disk space and directory writability before installs","Delete partial venv directories before retrying","Test `python -m venv /tmp/x` manually when troubleshooting"],"tags":["python","virtualenv","subprocess","dependency-install"],"backgroundTag":"venv-creation-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}