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 --version
Python 3.6.1
$ pip --version
pip 9.0.1 from /home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages (python 3.6)
$ pip install gi
Collecting gi
Downloading gi-1.2.tar.gz
Collecting requests (from gi)
Downloading requests-2.16.0-py2.py3-none-any.whl (85kB)
100% |████████████████████████████████| 92kB 959kB/s
Collecting idna<2.6,>=2.5 (from requests->gi)
Downloading idna-2.5-py2.py3-none-any.whl (55kB)
100% |████████████████████████████████| 61kB 1.2MB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests->gi)
Downloading chardet-3.0.3-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 1.8MB/s
Collecting urllib3<1.22,>=1.21.1 (from requests->gi)
Downloading urllib3-1.21.1-py2.py3-none-any.whl (131kB)
100% |████████████████████████████████| 133kB 1.8MB/s
Collecting certifi>=2017.4.17 (from requests->gi)
Downloading certifi-2017.4.17-py2.py3-none-any.whl (375kB)
100% |████████████████████████████████| 378kB 284kB/s
Installing collected packages: idna, chardet, urllib3, certifi, requests, gi
Running setup.py install for gi ... done
Successfully installed certifi-2017.4.17 chardet-3.0.3 gi-1.2 idna-2.5 requests-2.16.0 urllib3-1.21.1
Now, running the example:
$ python toolmanager.py
Traceback (most recent call last):
File "./toolmanager.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
_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 <module>
from . import backend_gtk3
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 10, in <module>
import gi
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/gi/__init__.py", line 39
print url
^
SyntaxError: Missing parentheses in call to 'print'
Seems like pip
somehow installed a Python 2 version? How can I fix this?
Install pip using Python 3's setuptools: run sudo easy_install3 pip , this will give you the command pip-3.2 like kev's solution. Install your PyPI packages: run sudo pip-3.2 install <package> (installing python packages into your base system requires root, of course). … Profit!
Most Python packages are now designed to be compatible with pip. If you have a package that's not compatible, then you'll need to do a manual installation. How to manually install a Python package: Download the package and extract it into a local directory.
The Pip Package Manager can be used to list both globally and locally installed Python packages.
The chosen answer is a little bit outdated as of now:
Installing the relevant package, plus its dependencies, depending on your environment, is still possible, just follow the steps from the doc.
But if you work from a venv, you might still stumble upon a ModuleNotFoundError: No module named 'gi'
when importing gi
. The venv ignores the system-wide module. Then simply run, from your venv: pip install PyGObject
(or use poetry
or your favorite python packages manager). Of course, you still need to have installed PyGObject's dependencies (see the link to the doc, right above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With