Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8658291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:43:43+00:00 2026-06-12T15:43:43+00:00

I’m having some strange issues with PyGTK in virtualenv. gtk does not import in

  • 0

I’m having some strange issues with PyGTK in “virtualenv”. gtk does not import in my virtualenv, while it does import in my global python install. (I wasn’t having this particular issue last week, guessing some software update upset something.)

Is there a good way to resolve this behavior?

Shown here: importing gtk globally,

tom@zeppelin:~$ python
Python 2.7.1+ (r271:86832, Sep 27 2012, 21:12:17) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtk
>>> gtk
<module 'gtk' from '/usr/lib/pymodules/python2.7/gtk-2.0/gtk/__init__.pyc'>

and then failing to import gtk,

tom@zeppelin:~$ workon py27
(py27)tom@zeppelin:~$ python
Python 2.7.1+ (r271:86832, Sep 27 2012, 21:12:17) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named gtk

Unfortunately, this has broken my ipython –pylab environment: http://pastebin.com/mM0ur7Hc

UPDATE:
I was able to fix this by adding symbolic links as suggested by grepic / this thread: Python: virtualenv – gtk-2.0

with a minor difference, namely that my “cairo” package was located in /usr/lib/pymodules/python2.7/cairo/ rather than in /usr/lib/python2.7/dist-packages/cairo.

SECOND UPDATE:
I also found it useful to add the following lines to my venv/bin/activate:

export PYTHONPATH=$PYTHONPATH:/home/tom/.virtualenvs/py27/lib/python2.7/dist-packages
export PYTHONPATH=$PYTHONPATH:/home/tom/.virtualenvs/py27/lib/python2.7/dist-packages/gtk-2.0
export PYTHONPATH=$PYTHONPATH:/usr/lib/pymodules/python2.7/gtk-2.0

(I suspect that one or more of these is unneccessary, but I’ve been fiddling around with this for too long and have decided to stop investigating — my setup now works and so I’m satisfied.)

Problem solved! Thanks everyone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:43:44+00:00Added an answer on June 12, 2026 at 3:43 pm

    So gtk normally lives in a place like /usr/lib/python2.7/dist-packages which is in your Python path in your global environment, but not in your virtual environment.

    You may wish to just add the path to gtk manually with something like

    import sys
    sys.path.append("/usr/lib/python2.7/dist-packages/gtk")
    

    You could also change the path when you activate the virtual environment. Open up venv/bin/activate. Its a scary looking file, but at the end you can just put:

    export PATH=$PATH:/my/custom/path
    

    Save that and the next time you activate the virtual environment with:

    source venv/bin/activate
    

    your custom path will be in the path. You can verify this with

    echo $PATH
    

    An alternative approach suggested Python: virtualenv – gtk-2.0 is to go into your virtualenv directory and add a ‘dist-packages’ directory and create symbolic links to the gtk package you were using previously:

    mkdir -p venv/lib/python2.7/dist-packages/
    cd venv/lib/python2.7/dist-packages/
    

    For GTK2:

    ln -s /usr/lib/python2.7/dist-packages/glib/ glib
    ln -s /usr/lib/python2.7/dist-packages/gobject/ gobject
    ln -s /usr/lib/python2.7/dist-packages/gtk-2.0* gtk-2.0
    ln -s /usr/lib/python2.7/dist-packages/pygtk.pth pygtk.pth
    ln -s /usr/lib/python2.7/dist-packages/cairo cairo
    

    For GTK3:

    ln -s /usr/lib/python2.7/dist-packages/gi gi
    

    Full disclosure: I feel that both these solutions are somewhat hackish, which is ok given that you say the question is urgent. There is probably a ‘proper’ way to extend a virtual environment so let us know if you eventually discover the better solution. You may have some luck with http://www.virtualenv.org/en/latest/index.html#creating-your-own-bootstrap-scripts

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.