title: No module 'gi' and ImportError: The GTK3 backends require PyGObject error
body: <p>I am trying to run some code on an AWS ec2 (ubuntu). When I comment out the portion that displays graphs from matplotlib, it runs fine. However, I want to view graphs.</p>
  <p>When running the code, I get this error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py&quot;, line 18, in &lt;module&gt;
      import gi
  ModuleNotFoundError: No module named 'gi'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;run.py&quot;, line 8, in &lt;module&gt;
      from process_mask import ProcessMasks
    File &quot;/home/ubuntu/rPPG/process_mask.py&quot;, line 10, in &lt;module&gt;
      matplotlib.use('GTK3Agg')
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py&quot;, line 307, in wrapper
      return func(*args, **kwargs)
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/__init__.py&quot;, line 1307, in use
      switch_backend(name)
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/pyplot.py&quot;, line 221, in switch_backend
      backend_mod = importlib.import_module(backend_name)
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/importlib/__init__.py&quot;, line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3agg.py&quot;, line 4, in &lt;module&gt;
      from . import backend_agg, backend_cairo, backend_gtk3
    File &quot;/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py&quot;, line 20, in &lt;module&gt;
      raise ImportError(&quot;The GTK3 backends require PyGObject&quot;)
  ImportError: The GTK3 backends require PyGObject
  </code></pre>
  <p>I've been searching SO and other sources and have tried a lot of things including:</p>
  <pre><code>sudo apt-get install python3-gi
  
  pip install vext
  pip install vext.gi
  
  sudo apt install python3-gi
  
  pip3 install --user pgi
  </code></pre>
  <p>Also, this works:</p>
  <pre><code>$ /usr/bin/python3
  Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
  [GCC 4.8.2] on linux
  Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  &gt;&gt;&gt; import gi
  &gt;&gt;&gt; 
  </code></pre>
  <p>but my actual code is in a virtual env with a bunch of dependencies, so this doesn't work with my actual code (<code>/usr/bin/python run.py</code>).</p>