Why when import pygame, it prints the version and welcome message. How delete it?
Solution 1:
It works for me:
import os
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import pygame
Solution 2:
I didn't see a natural way to do it (yours is the only Google result for this that I could find), but I did achieve the same thing by temporarily disabling stdout while importing pygame.
import os, sys
with open(os.devnull, 'w') as f:
# disable stdout
oldstdout = sys.stdout
sys.stdout = f
import pygame
# enable stdout
sys.stdout = oldstdout
Here's the alternative suggested by @Mad Physicist:
import contextlib
with contextlib.redirect_stdout(None):
import pygame
Solution 3:
The source code contains a condition guarding the printing of this message:
if 'PYGAME_HIDE_SUPPORT_PROMPT' not in os.environ:
print('pygame %s' % ver)
print('Hello from the pygame community. https://www.pygame.org/contribute.html')
See this commit
This was added fairly recently (October 2018) and so far 1.9.4 was released prior to this. Once the next version > 1.9.4 is released you should simply by able to run your code with PYGAME_HIDE_SUPPORT_PROMPT= ./my_code.py
to hide the message.
Solution 4:
You can navigate to the pygame library folder, something like this for 3.6 32 bit version:
Python36-32\Lib\site-packages\pygame
and edit the __init__.py
file and remove the last line to get rid of this message.