Skip to content

PYTHONSAFEPATH makes the target debug report drop the first real sys.path entry #3584

Closed

Description

@Pratik-Kumar-Dhakar

Issue

With PYTHONSAFEPATH=1 set (Python 3.11+), the target debug report (-vv and Creator.debug) drops the first real sys.path entry of the new environment:

$ for v in "" 1; do PYTHONSAFEPATH=$v python -c "
from virtualenv import cli_run
s = cli_run(['--no-seed', '--activators', '', '-p', 'python3.12', 'sp$v'], setup_logging=False)
print(repr('$v'), s.creator.debug['sys']['path'][:2])"; done
'' ['.../lib/python312.zip', '.../lib/python3.12']
'1' ['.../lib/python3.12', '.../lib/python3.12/lib-dynload']
$ sp1/bin/python -c 'import sys; print(sys.path[1:3])'
['.../lib/python312.zip', '.../lib/python3.12']

With the variable set, python312.zip is missing from the report, although the environment does have it on sys.path. -vv prints the same list.

get_env_debug_info (create/creator.py) deletes sys.path[0], assuming it is the debug script's directory. Safe-path mode never adds that directory, so a real entry is deleted instead. The same function already unsets PYTHONPATH for this report (#3473); PYTHONSAFEPATH needs the same treatment.

Environment

  • OS: Zorin OS 17.3 (Ubuntu 22.04 base), Linux 6.8
  • Shell: bash 5.1
  • Python version and path: CPython 3.15.2 (uv-managed)
  • virtualenv: main @ 53748fe (21.15.9)

Activity

  1. added a commit that references this issue on Nov 20, 2026
    f0f7b8e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions