M BUZZ CRAZE NEWS
// general

How to install gi for anaconda python3.6

By David Jones

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 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'
>>> 
1

1 Answer

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
>>> 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy