我查看了this,并尝试了以下代码:
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/
,但import glib
或import gi
仍会产生错误:
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
>>>
与该帖子类似,系统范围的python工作正常:
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
>>>
如何解决这个问题?另外,我真正需要的是import gi.repository
而不是import gi
。非常感谢!
答案 0 :(得分:-2)
您需要在虚拟环境中安装必要的模块。
激活后,您必须pip install <library name>
。在您的情况下,它应该是pip install gi
答案 1 :(得分:-2)
首先,请记住,虚拟环境(2.7.9)使用的Python与系统范围的Python(2.7.6)不同,所以我没有看到制作一个他们之间的比较。
您可以做的一件事是从头开始创建虚拟环境,但使用-p
标志来指示应使用哪个Python版本。像这样:
virtualenv -p /usr/bin/python2.7 <virtualenv/new/path/>
其次,使用2.7.9版本报告的undefined symbol: PyUnicodeUCS4_FromUnicode
错误可能与Python源的不正确编译有关。请尝试重新编译它们,但要注意--enable-unicode=ucs4
行中的./configure
选项:
$> tar -xf Python-2.7.6.tar
$> cd Python-2.7.6
$> ./configure --prefix=/usr/local --enable-shared --enable-unicode=ucs4
$> make && make altinstall