Skip to content

Prevent using system Python despite venv check#407

Open
Mikolaj-A-Kowalski wants to merge 1 commit intoCambridge-ICCS:mainfrom
Mikolaj-A-Kowalski:safe-virtualenv-error
Open

Prevent using system Python despite venv check#407
Mikolaj-A-Kowalski wants to merge 1 commit intoCambridge-ICCS:mainfrom
Mikolaj-A-Kowalski:safe-virtualenv-error

Conversation

@Mikolaj-A-Kowalski
Copy link
Copy Markdown
Member

Previously a system Python could be used despite the protection if one:

  1. Tried to run the cmake without venv
  2. Activated venv after seeing the error message
  3. Re-run the cmake without cleaning cache

Now check for venv is done before any search for Python so nothing will be cached.

I have also used this opportunity to change the Python_FIND_VIRTUALENV to ONLY which is I believe the behaviour we want (never pick-up the system interpreter in any case?)

@Mikolaj-A-Kowalski Mikolaj-A-Kowalski added bug Something isn't working build Related to installing/building FTorch and its dependencies labels Jul 21, 2025
Previously a system Python could be used despite the protection if one:
1) Tried to run the `cmake` without venv
2) Activated venv after seeing the error message
3) Re-run the cmake without cleaning cache

Now check for venv is done before any search for Python so nothing will
be cached.
Change VIRTUALENV option to ONLY to prevent using system python in any
case.
Comment thread CMakeLists.txt
# environment variable exists
# Must be done before `find_package` in to prevent system Python getting
# cached by CMake
if(NOT DEFINED ENV{VIRTUAL_ENV})
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make it work with conda environment as well?
But for that we will need to increase minimum CMake version 3.17 since this is when FindPython FIND_VIRTUALENV got support for conda.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with bumping the minimum version to 3.17. We could also plausibly increase the maximum version given how many more releases there have been since 3.31 https://cmake.org/cmake/help/latest/release/index.html

Copy link
Copy Markdown
Member

@jatkinson1000 jatkinson1000 Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine, but can we ideally have a separate commit and definitely a Changelog entry for it please.

Looking at the breaking changes for 4.0 we should be unaffected.

@Mikolaj-A-Kowalski
Copy link
Copy Markdown
Member Author

I was thinking that perhaps the cleanest and safest check for the virtual environment would be to set the
PIP_REQUIRE_VEN in the examples CMakeList.txts?

Copy link
Copy Markdown
Collaborator

@joewallwork joewallwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, thanks @Mikolaj-A-Kowalski! Please could you tweak the CMake versions as mentioned?

Comment thread CMakeLists.txt
# environment variable exists
# Must be done before `find_package` in to prevent system Python getting
# cached by CMake
if(NOT DEFINED ENV{VIRTUAL_ENV})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with bumping the minimum version to 3.17. We could also plausibly increase the maximum version given how many more releases there have been since 3.31 https://cmake.org/cmake/help/latest/release/index.html

Copy link
Copy Markdown
Member

@jatkinson1000 jatkinson1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks sensible to me.
Just ensure changelog is updated with the CMake version bump please.

Comment thread CMakeLists.txt
# environment variable exists
# Must be done before `find_package` in to prevent system Python getting
# cached by CMake
if(NOT DEFINED ENV{VIRTUAL_ENV})
Copy link
Copy Markdown
Member

@jatkinson1000 jatkinson1000 Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine, but can we ideally have a separate commit and definitely a Changelog entry for it please.

Looking at the breaking changes for 4.0 we should be unaffected.

@jatkinson1000
Copy link
Copy Markdown
Member

@Mikolaj-A-Kowalski just looked at the conflict and it looks like a conda check has been added in which might circumvent the need to bump and simplify your PR if you want to rebase on main and reassess.

@jatkinson1000
Copy link
Copy Markdown
Member

@Mikolaj-A-Kowalski any chance you might have a moment to look at this as a small hanging PR.
Trying to get a few things mopped up.

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

Labels

bug Something isn't working build Related to installing/building FTorch and its dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants