How to install pygtk within virtualenv?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 16:22:30

问题


I installed ipython in a virtual env (1.13 with 2.7.2) and tried ipython -gui=gtk but still got the basic terminal interface with no %paste support for example.

Now I tried installing pygtk but no success there either.

I'm running Crunchbang linux with OpenBox WM.

    [TerminalIPythonApp] GUI event loop or pylab initialization failed
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
...python2.7/local/lib/python2.7/site-packages/IPython/lib/inputhook.pyc in enable_gui(gui, app)
    526         e = "Invalid GUI request %r, valid ones are:%s" % (gui, guis.keys())
    527         raise ValueError(e)
--> 528     return gui_hook(app)
    529 

...python2.7/local/lib/python2.7/site-packages/IPython/lib/inputhook.pyc in enable_gtk(self, app)
    286         IPython.
    287         """
--> 288         import gtk
    289         try:
    290             gtk.set_interactive(True)

ImportError: No module named gtk

I've tried to pip install pygtk within the virtualenv I've activated but no luck.

Full log:

$ pip install pygtk
Downloading/unpacking pygtk
  Downloading pygtk-2.24.0.tar.bz2 (2.4MB): 2.4MB downloaded
  Running setup.py egg_info for package pygtk
    ********************************************************************
    * Building PyGTK using distutils is only supported on windows. *
    * To build PyGTK in a supported way, read the INSTALL file.    *
    ********************************************************************
    Complete output from command python setup.py egg_info:
    ********************************************************************

* Building PyGTK using distutils is only supported on windows. *

* To build PyGTK in a supported way, read the INSTALL file.    *

********************************************************************

----------------------------------------
Command python setup.py egg_info failed with error code 1 in ...python2.7/build/pygtk

回答1:


Since you are running a debian-based distribution; you can save yourself some headaches and simply sudo apt-get install ipython (and sudo apt-get install ipython3 if you want to play with Python 3).

This will ensure that the proper GTK bindings are installed as well. This is the most supported way.

Latest versions of ipython have auto-detection of virtualenvironments.




回答2:


I first installed gi with pip (on ubuntu) and got the same error, without a virtualenv. My solution was to uninstall gi: sudo -H pip uninstall gi and then install using: sudo apt-get install --reinstall python-gi



来源:https://stackoverflow.com/questions/13782776/how-to-install-pygtk-within-virtualenv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!