How to install python "gi" module in virtual environment?
<p>I have looked at <a href="http://stackoverflow.com/questions/12830662/python-package-installed-globally-but-not-in-a-virtualenv-pygtk">this</a>, and tried the following code:</p>

<pre><code>ln -s /usr/lib/python2.7/dist-packages/pygtk.pth tools/python_2_7_9/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/gobject tools/python_2_7_9/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/gtk-2.0 tools/python_2_7_9/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/pygtk.pth tools/python_2_7_9/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/glib tools/python_2_7_9/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/gi tools/python_2_7_9/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/pygtkcompat tools/python_2_7_9/lib/python2.7/site-packages/
</code></pre>

<p>,but <code>import glib</code> or <code>import gi</code> still generates errors:</p>

<pre><code>yba@ubuntu:~/Documents/XXX/tools$ source python_2_7_9/bin/activate
(python_2_7_9) yba@ubuntu:~/Documents/XXX/tools$ python
Python 2.7.9 (default, Aug 29 2016, 16:04:36) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import glib
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/yba/Documents/XXX/tools/python_2_7_9/lib/python2.7/dist-packages/glib/__init__.py", line 22, in &lt;module&gt;
    from glib._glib import *
ImportError: /home/yba/Documents/XXX/tools/python_2_7_9/lib/python2.7/dist-packages/glib/_glib.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8
&gt;&gt;&gt; import gi
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/yba/Documents/XXX/tools/python_2_7_9/lib/python2.7/dist-packages/gi/__init__.py", line 36, in &lt;module&gt;
    from ._gi import _gobject
ImportError: /home/yba/Documents/lucida/tools/python_2_7_9/lib/python2.7/dist-packages/gi/_gi.so: undefined symbol: PyUnicodeUCS4_FromUnicode
&gt;&gt;&gt; 
</code></pre>

<p>Similar to that post, the system-wide python works fine:</p>

<pre><code>yba@ubuntu:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import gi
&gt;&gt;&gt; import glib
&gt;&gt;&gt; 
</code></pre>

<p>How to solve this issue? Also, what I really need is <code>import gi.repository</code> rather than <code>import gi</code>. Thanks a lot!</p>

<p>You need to install the necessary modules on your virtual environment. </p>

<p>After activating it, you have to <code>pip install &lt;library name&gt;</code>. In your case, it should be <code>pip install gi</code></p>

python virtualenv python-gstreamer