Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install python "gi" module in virtual environment?

I have looked at this, and tried the following 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/

,but import glib or import gi still generates errors:

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.
>>> import glib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yba/Documents/XXX/tools/python_2_7_9/lib/python2.7/dist-packages/glib/__init__.py", line 22, in <module>
    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
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yba/Documents/XXX/tools/python_2_7_9/lib/python2.7/dist-packages/gi/__init__.py", line 36, in <module>
    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
>>> 

Similar to that post, the system-wide python works fine:

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.
>>> import gi
>>> import glib
>>> 

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

like image 583
Yunsheng Bai Avatar asked Oct 30 '22 21:10

Yunsheng Bai


1 Answers

It is now possible to resolve this using vext. Vext allows you to install packages in a virtualenv that individually access your system packages. To access gi, do the following:

pip install vext
pip install vext.gi
like image 136
lofidevops Avatar answered Nov 15 '22 05:11

lofidevops