0

When I import pyBullet, it immediately prints a line with the time when it was build:

In [1]: import pybullet
pybullet build time: Jun 19 2020 04:01:58

Is there a way to prevent this?

luator
  • 4,769
  • 3
  • 30
  • 51

2 Answers2

1

Change the source code. Jokes aside, I think there is no obivious way to prevent this from happening. Since it happens when you import the module, there is not much you can do in configuration of pybullet. Because it is literally the first thing you do with it.

Maybe you can reroute stdout during the import of the module. Which is a duplicate question already answered here: Stop Python Module from Printing

tjallo
  • 781
  • 6
  • 25
  • 1
    I found [this issue](https://github.com/bulletphysics/bullet3/issues/2480) about the print. Editing the code really seems the only option so far. The rerouting of stdout did unfortunately not work, probably because the print is coming from the underlying C code, not from Python. – luator Jul 01 '20 at 11:30
0

Check these solutions on a similar problem with pygame.

Why when import pygame, it prints the version and welcome message. How delete it?

Based on this, I suggest to try:

import contextlib
with contextlib.redirect_stdout(None):
    import pybullet

full credit to MadPhysicist

Omar Silva
  • 100
  • 3
  • 11
  • Unfortunately, this does not work, the print still shows up. I assume it's because the print comes from the underlying C code, so Python has no control over it (see my comment on tjallo's answer). – luator Sep 28 '20 at 11:39