✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Plotly orca xvfb failed to run (For some reason plotly.py was unable to communicate)

I know this is a question that have been asked before, But non of the previous solutions worked.

I’m trying to save a plotly image to a static file.

The following error returns in multiple configurations and hacks I tried (the attempts are described below):

Exception has occurred: ValueError

For some reason plotly.py was unable to communicate with the
local orca server process, even though the server process seems to be running.

Please review the process and connection information below:

orca status
-----------
    state: running
    executable: /usr/bin/xvfb-run --auto-servernum --server-args -screen 0 640x480x24 +extension RANDR +extension GLX /home/user/anaconda3/envs/CPD_1/bin/orca
    version: 1.2.1
    port: 45239
    pid: 19512
    command: ['/usr/bin/xvfb-run', '--auto-servernum', '--server-args', '-screen 0 640x480x24 +extension RANDR +extension GLX', '/home/user/anaconda3/envs/CPD_1/bin/orca', 'serve', '-p', '45239', '--plotly', '/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/plotly/package_data/plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']


  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/plotly/io/_orca.py", line 1594, in to_image
    info=status_str
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/plotly/io/_orca.py", line 1770, in write_image
    fig, format=format, scale=scale, width=width, height=height, validate=validate
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3193, in write_image
    return pio.write_image(self, *args, **kwargs)
  File "/home/user/repos/CPD/visualization/mesh_visualization/mesh_visualizer.py", line 189, in visualize_mesh_pair
    fw.write_image(save_path)
  File "/home/user/repos/CPD/models/shape_correspondence_pl_template.py", line 324, in visualize_pair_corr
    save_path=image_path,
  File "/home/user/repos/CPD/models/shape_correspondence_pl_template.py", line 148, in training_step
    P,
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/overrides/data_parallel.py", line 58, in forward
    return self.module.training_step(*inputs[0], **kwargs[0])
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 710, in training_forward
    output = self.model(*args)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 563, in optimizer_closure
    output_dict = self.training_forward(split_batch, batch_idx, opt_idx, self.hiddens)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 599, in run_training_batch
    loss, batch_output = optimizer_closure()
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 421, in run_training_epoch
    _outputs = self.run_training_batch(batch, batch_idx)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 349, in train
    self.run_training_epoch()
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1033, in run_pretrain_routine
    self.train()
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/distrib_parts.py", line 575, in dp_train
    self.run_pretrain_routine(model)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 869, in fit
    self.dp_train(model)
  File "/home/user/repos/CPD/train.py", line 174, in main_train
    trainer.fit(model)
  File "/home/user/repos/CPD/train.py", line 75, in main
    main_train(model_class_pointer, hyperparams, logger)
  File "/home/user/repos/CPD/train.py", line 183, in <module>
    main()
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/anaconda3/envs/CPD_1/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)

The things I’ve attempted:

1 ) Create a orca_xvfb.bash with the following content (inside conda/envs/env/bin):

#!/bin/bash
/usr/bin/xvfb-run --auto-servernum --server-args="-screen 0 640x480x24 +extension RANDR +extension GLX" ~/anaconda3/envs/CPD_1/bin/orca "$@"

and add plotly.io.orca.config.executable = 'orca_xvfb.bash'

2 ) Open xvfb manually, meaning:
2.1 ) import subprocess;os.environ["DISPLAY"]=":0";xvfb = subprocess.Popen(['Xvfb', ':0']);
or
2.2 )from xvfbwrapper import Xvfb; vdisplay = Xvfb(); vdisplay.start()

But all of the above did not worked.

Ubuntu 18.04
plotly 4.7.1