Skip to content

Failed to run built Python - AttributeError: module 'sys' has no attribute 'winver' #431

@Andrej730

Description

@Andrej730

Tested on 3.12.10 and 3.11.0 - build suceeds, but there are some AttributeError: module 'sys' has no attribute 'winver' errors during installation (I assume when Python itself is executed to launch some commands / do tests) and running any commands to already installed Python fails with the same error.

Below is .yml for github action to reproduce the problem:

name: build-cmake-python

on:
  workflow_dispatch:

jobs:
  build-cmake-python:
    runs-on: windows-2022

    steps:
    - name: Configure build
      run: |
        Set-PSDebug -Trace 1
        $ErrorActionPreference = "Stop"
        $PSNativeCommandUseErrorActionPreference = $true

        curl -L https://raw.githubusercontent.com/Andrej730/vcvarsall-pwsh/refs/heads/master/generate-vcvarsall-env.ps1 -o generate-vcvarsall-env.ps1
        pwsh -NoProfile -File .\generate-vcvarsall-env.ps1
        . .\vcvarsall-env.ps1

        git clone https://github.com/python-cmake-buildsystem/python-cmake-buildsystem --depth 1
        cd python-cmake-buildsystem
        mkdir build && cd build
        cmake .. -DCMAKE_INSTALL_PREFIX="install"
        cmake --build . --config Release -- /m
        cmake --install . --config Release
        ./install/bin/python.exe --version
        ./install/bin/python.exe -c "print(42)"

Here are example logs - https://github.com/Andrej730/artifact-test-repo/actions/runs/19988079925/job/57324841696

Python runtime state: initialized
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1176, in exec_module
  File "<frozen site>", line 636, in <module>
  File "<frozen site>", line 622, in main
  File "<frozen site>", line 361, in addusersitepackages
  File "<frozen site>", line 348, in getusersitepackages
  File "<frozen site>", line 313, in _get_path
AttributeError: module 'sys' has no attribute 'winver'
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/Lib/Tools/scripts/run_tests.py
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/bin/venvlauncher.exe
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/bin/venvwlauncher.exe
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/bin/pylauncher.exe
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/bin/pywlauncher.exe
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/Lib/lib-dynload
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/share/python312/PythonTargets.cmake
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/share/python312/PythonTargets-release.cmake
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/share/python312/PythonConfig.cmake
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/share/python312/PythonConfigVersion.cmake
-- Installing: D:/a/artifact-test-repo/artifact-test-repo/python-cmake-buildsystem/build/install/Lib/LICENSE.txt
DEBUG:   16+  >>>> ./install/bin/python.exe --version

Python 3.12.10
DEBUG:   17+  >>>> ./install/bin/python.exe -c "print(42)"

Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1176, in exec_module
  File "<frozen site>", line 636, in <module>
  File "<frozen site>", line 622, in main
  File "<frozen site>", line 361, in addusersitepackages
  File "<frozen site>", line 348, in getusersitepackages
  File "<frozen site>", line 313, in _get_path
AttributeError: module 'sys' has no attribute 'winver'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions