2301_80122206 2025-05-17 08:39 采纳率: 33.3%
浏览 52

pygame报错avx2不被支持

  1. 在pycharm运行时报错
    :488: RuntimeWarning: Your system is avx2 capable but pygame was not built with support for it. The performance of some of your blits could be adversely affected. Consider enabling compile time detection with environment variables like PYGAME_DETECT_AVX2=1 if you are compiling without cross compilation.
    pygame 2.6.1 (SDL 2.32.54, Python 3.12.10)
    Hello from the pygame community. https://www.pygame.org/contribute.html
    Traceback (most recent call last):
    File "D:\PythonProject\start.py", line 5, in
    print(pygame.get_sdl_avx2_enabled()) # 输出 True 表示已启用
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    AttributeError: module 'pygame' has no attribute 'get_sdl_avx2_enabled'

2.代码


```python
import pygame, sys
from pygame.locals import *  # 导入事件常量(包括 QUIT)
PYGAME_DETECT_AVX2=1
pygame.init()
# print(pygame.get_sdl_avx2_enabled())  # 输出 True 表示已启用
screen = pygame.display.set_mode((600, 400))

pygame.display.set_caption("Pygame welcome you!")

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            sys.exit()
    pygame.display.update()

3. 环境以及配置
运行脚本文件位于:D:\PythonProject
解释器选择的是:conda的虚拟环境的3.12的python
pygame的版本:pygame       2.6.1           py312hea106ac_0    conda-forge
  • 写回答

4条回答 默认 最新

  • 阿里嘎多学长 2025-05-17 08:39
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    pygame报错avx2不被支持

    你遇到的问题是 Pygame 在 PyCharm 中运行时报错,提示系统支持 AVX2 但 Pygame 没有被编译支持 AVX2。

    解决方案:

    1. 检查 Pygame 的安装方式:如果你使用 pip 安装 Pygame,可能需要重新安装 Pygame 使用以下命令:
    pip install --upgrade pygame --force-reinstall
    
    1. 检查 Pygame 的编译选项:你可以检查 Pygame 的编译选项是否包含 --avx2 选项。如果没有,可以重新编译 Pygame:
    python setup.py build_ext --inplace --avx2
    
    1. 使用 Pygame 的 alternative 版本:如果上述方法不行,可以尝试使用 Pygame 的 alternative 版本,例如 pygame-1.9.6,它支持 AVX2:
    pip install pygame-1.9.6
    
    1. 使用 PyCharm 的配置:在 PyCharm 中,检查项目的配置是否正确,确保 Pygame 的路径正确。

    如果你遇到其他问题,可以提供更多的信息,我将尽力帮助你解决问题。

    评论

报告相同问题?

问题事件

  • 创建了问题 5月17日