Skip to content

PYTHONPATH values set in host can break pdm run #3742

@cgranade

Description

@cgranade

Describe the bug

If the PYTHONPATH environment variable is set on the host, that can propagate to programs run by PDM; for example, this appears to be the root cause of pyinstaller/pyinstaller#9389, where nix-shell manipulates PYTHONPATH to make Nix packages available to installation of Python on PATH (this is probably not an optimal way to do things, I plan on filing an issue with Nix as well), causing pdm run pyinstaller to see both Nix-managed and PDM-managed site-packages in the same invocation.

To reproduce

This was observed while working on the Arcalibre repository. To reproduce:

$ git clone https://codeberg.org/rereading/arcalibre.git
$ cd arcalibre
$ git checkout cgranade/installer
$ nix-shell
$ pdm sync --dev
$ cd installer
$ pdm run pyinstaller arcalibre.py

Expected Behavior

The PYTHONPATH variable set from outside the PDM-managed venv would not be visible to programs run by pdm run.

Environment Information

PDM version:
  2.26.1
Python Interpreter:
  /home/cgranade/repos/codeberg/rereading/arcalibre/.venv/bin/python (3.14)
Project Root:
  /home/cgranade/repos/codeberg/rereading/arcalibre
Local Packages:
  /home/cgranade/repos/codeberg/rereading/arcalibre/.venv/lib/python3.14/site-pa
ckages
{
  "implementation_name": "cpython",
  "implementation_version": "3.12.11",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "6.17.0-14-generic",
  "platform_system": "Linux",
  "platform_version": "#14-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan  9 17:01:16 UTC 
2026",
  "python_full_version": "3.14.3",
  "platform_python_implementation": "CPython",
  "python_version": "3.14",
  "sys_platform": "linux"
}

Verbose Command Output

No response

Additional Context

No response

Are you willing to submit a PR to fix this bug?

  • Yes, I would like to submit a PR.

Metadata

Metadata

Assignees

Labels

🐛 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions