BME280 not working with Mega powered with 9v battery

Can you try a delay at the start of setup() ?
You can send a message to the serial monitor and then do the delay.

void setup()
{
  Serial.begin( 9600);          // 9600 is default but slow, 115200 baud is better
  Serial.println( "The sketch has started");

  delay( 1000);

  ...
}