Skip to content

Fix: Preserve environment markers when importing requirements.txt#6489

Merged
matteius merged 1 commit intomainfrom
fix/requirements-markers-6101
Dec 10, 2025
Merged

Fix: Preserve environment markers when importing requirements.txt#6489
matteius merged 1 commit intomainfrom
fix/requirements-markers-6101

Conversation

@matteius
Copy link
Copy Markdown
Member

Summary

When using pipenv install -r requirements.txt with packages that have environment markers (e.g., python-magic-bin; sys_platform == 'win32'), the markers were being ignored and the package was added to Pipfile without them.

Problem

The generate_package_pipfile_entry() function in pipenv/project.py wasn't extracting the markers attribute from the InstallRequirement object when creating the Pipfile entry.

Before:

[packages]
python-magic-bin = "*"

After:

[packages]
python-magic-bin = {version = "*", markers = "sys_platform == 'win32'"}

Changes

  1. pipenv/project.py: Added marker extraction in generate_package_pipfile_entry() to include the package.markers attribute in the Pipfile entry when present.

  2. tests/integration/test_import_requirements.py: Added a test to verify that environment markers are preserved when importing from requirements.txt.

Test

pipenv run pytest tests/integration/test_import_requirements.py::test_import_requirements_preserves_markers -v

Fixes #6101


Pull Request opened by Augment Code with guidance from the PR author

When using 'pipenv install -r requirements.txt' with packages that have
environment markers (e.g., 'python-magic-bin; sys_platform == "win32"'),
the markers were being ignored and the package was added to Pipfile
without them.

The fix adds marker extraction in generate_package_pipfile_entry() to
include the package.markers attribute in the Pipfile entry when present.

Example: 'python-magic-bin; sys_platform == "win32"' in requirements.txt
now correctly produces:
  python-magic-bin = {version = "*", markers = "sys_platform == 'win32'"}

Fixes #6101
@matteius matteius merged commit eded091 into main Dec 10, 2025
19 of 20 checks passed
@matteius matteius deleted the fix/requirements-markers-6101 branch December 10, 2025 22:15
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.

pipenv install -r requirements.txt not respecting sys_platform

1 participant