Python 3: Installing gi package with pip

前端 未结 2 565
名媛妹妹
名媛妹妹 2020-12-16 19:41

I am trying to run this Matplotlib example using Python 3. To run this I needed to install gi first (I am using pyenv):

$ python --         


        
2条回答
  •  情书的邮戳
    2020-12-16 20:31

    First, pip install gi will install another unrelated package, the correct name is pgi. But after running:

    $ pip uninstall gi
    $ pip install pgi
    $ python toolmanager.py
    [...]
    Traceback (most recent call last):
      File "toolmanager.py", line 14, in 
        import matplotlib.pyplot as plt
      File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in 
        _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
      File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
        globals(),locals(),[backend_name],0)
      File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3cairo.py", line 6, in 
        from . import backend_gtk3
      File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 12, in 
        raise ImportError("Gtk3 backend requires pygobject to be installed.")
    ImportError: Gtk3 backend requires pygobject to be installed.
    

    It seems that pygobject for Python 3 cannot be installed from PyPI. So I tried to install everything from the Ubuntu distribution package python3-gi instead:

    $ sudo apt-get install python3-gi
    $ pyenv local system
    $ python3 --version
    Python 3.5.3
    $ python3 toolmanager.py
    

    and this works fine :)

提交回复
热议问题