Python3 cannot import gi

11,158

Solution 1

python packages installed system-wide may not be available for python versions installed in anaconda directories.

Try instead to load your script using the full path to the system interpreter:

$ /usr/bin/python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> 

Solution 2

Some packages like gi does not exist in the conda environment directory after installation but the system's Python directory. You could use conda-forge to install the package so that could run it directly from your conda Python 3 environment.

conda install -c conda-forge pygobject
Share:
11,158

Related videos on Youtube

Tyler Berezowsky
Author by

Tyler Berezowsky

Updated on September 18, 2022

Comments

  • Tyler Berezowsky
    Tyler Berezowsky over 1 year

    I was attempting to run an indicator for pushbullet without avail. I attempted to run through the terminal when I noticed python3 can not import gi

    bin > python3 pushbullet-indicator
    Traceback (most recent call last):
     File "pushbullet-indicator", line 26, in <module>
     import gi
     ImportError: No module named 'gi'
    bin > 
    

    Attempting a manual import.

    ~ > python3
    Python 3.4.1 (default, Sep 27 2014, 09:00:29) 
    [GCC 4.8.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import gi
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named 'gi'
    >>> 
    

    but for some reason Python2 can?

    Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
    [GCC 4.8.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import gi
    >>> 
    

    I have Anaconda installed. I'm attempting to import gi on the system's install of python3. I hope that is the correct terminology. python3-gi is installed.

    Even stranger is that I can run indicator-cpufreq

    Do you guys have any ideas or recommendations? Thanks for any help!

  • Tyler Berezowsky
    Tyler Berezowsky about 9 years
    I'm not sure I entirely understand. Anaconda added ~/anaconda/bin to my path. grepping for python, it appears only the following commands would be over written. bin > ls | grep python activate-global-python-argcomplete ipython ipython2 python python2 python2.7 python-argcomplete-check-easy-install-script python-config register-python-argcomplete bin > ]^C bin >
  • RobotHumans
    RobotHumans about 9 years
    Anaconda works by overriding your global python environment and using only the share in your ~/Anaconda subfolders. gir is notoriously hard to build/install in a venv... so, to use your global python env, you have to disable that env mangling anaconda puts in your bashrc.
  • Carl H
    Carl H over 3 years
    This is the correct answer. If you're using Anaconda, don't install Python packages directly, install them into Anaconda and use that at all times. Otherwise you can end up in a right mess.