How to install gi for anaconda python3.6

6,338

I have had the very same problem today and what worked for me is the following:

First, create the link, as suggested in the stackoverflow post you cited (assuming that anaconda is installed under /home/your_user/anaconda3)

ln -s /usr/lib/python3/dist-packages/gi /home/your_user/anaconda3/lib/python3.6/site-packages/

Secondly, navigate into the gi folder that you just linked, within your anaconda directory and rename a copy of the two .so files to fit the python-version of anaconda (in my case from 3.4 to 3.6)

cd /home/your_user/anaconda3/lib/python3.6/site-packages/gi/

sudo cp _gi.cpython-34m-x86_64-linux-gnu.so _gi.cpython-36m-x86_64-linux-gnu.so

and

sudo cp _gi_cairo.cpython-34m-x86_64-linux-gnu.so _gi_cairo.cpython-36m-x86_64-linux-gnu.so

Finally, the import gi worked accordingly within my anaconda environment.

Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.  
>>> import gi
>>> 
Share:
6,338

Related videos on Youtube

George LongIsland
Author by

George LongIsland

Updated on September 18, 2022

Comments

  • George LongIsland
    George LongIsland over 1 year

    in Ubuntu 16.04 I have python2.7, python3.5 and python3.6. Anaconda is using python3.6. I can import gi on 2.7 and 3.5, but I can't in 3.6. I created the link as suggested here https://stackoverflow.com/questions/37526026/how-to-install-gi-module-for-anaconda-python3 but I still get an error.

    gio@gio-XPS-13-9343:~$ python
    Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
    [GCC 7.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import gi
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/home/gio/anaconda3/lib/python3.6/site-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
    ImportError: cannot import name '_gi'
    >>> 
    
    • George LongIsland
      George LongIsland over 5 years
      I switched to use PyQt instead of gi for my GUI
  • Chang
    Chang over 4 years
    You saved my life.