无法初始化 Pygame 显示,但只能在 运行 时通过 tox
Unable to initialize Pygame display, but only when running through tox
我有以下最小测试程序。
import pygame
pygame.init()
print(pygame.display.list_modes())
如果我尝试通过 Tox 命令 运行 这个程序,我得到错误:
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(pygame.display.list_modes())
pygame.error: video system not initialized
但是,如果我手动激活虚拟环境中的 tox 命令 运行s 和 运行 相同的程序,它会按预期工作。我希望这两个执行环境是相同的。我做错了什么?
为了解决这个问题,我需要添加一个
passenv = DISPLAY
给我的 [testenv]
.
如上面的评论所述,tox
执行 isolated
构建,并且不传递 ENVIRONMENT
变量,除非您将它们列入白名单。
我不是很熟悉pygame
,我只是快速浏览了一下源代码。
这适用于我的机器 Ubuntu - 也许它与您的设置不同。
我有以下最小测试程序。
import pygame
pygame.init()
print(pygame.display.list_modes())
如果我尝试通过 Tox 命令 运行 这个程序,我得到错误:
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(pygame.display.list_modes())
pygame.error: video system not initialized
但是,如果我手动激活虚拟环境中的 tox 命令 运行s 和 运行 相同的程序,它会按预期工作。我希望这两个执行环境是相同的。我做错了什么?
为了解决这个问题,我需要添加一个
passenv = DISPLAY
给我的 [testenv]
.
如上面的评论所述,tox
执行 isolated
构建,并且不传递 ENVIRONMENT
变量,除非您将它们列入白名单。
我不是很熟悉pygame
,我只是快速浏览了一下源代码。
这适用于我的机器 Ubuntu - 也许它与您的设置不同。