我尝试使用Python 3运行this Matplotlib示例。要运行此示例,我需要先安装gi
(我使用的是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
现在,运行示例:
$ 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'
似乎pip
以某种方式安装了Python 2版本?我如何修复这个问题?
4条答案
按热度按时间qvk1mo1f1#
首先,
pip install gi
将安装另一个不相关的软件包,正确的名称是pgi
。但运行后:Python 3的
pygobject
似乎不能从PyPI安装。所以我尝试从Ubuntu分发包python3-gi
安装所有内容:这个很好用:)
bf1o4zei2#
chosen answer现在有点过时了:
根据您的环境,仍然可以安装相关的软件包及其依赖项,只需遵循steps from the doc。
但是如果你使用venv,在导入
gi
时,你仍然可能会遇到ModuleNotFoundError: No module named 'gi'
。venv会忽略系统范围的模块。然后简单地运行,从你的venv:pip install PyGObject
(或者使用poetry
或你喜欢的python包管理器)。当然,你仍然需要安装PyGObject的依赖项(参见上面的文档链接)。mgdq6dx13#
要安装标准python,Håkon Hægland answer是最佳选择。
但是对于alternate python version,可以使用
pip<version>
。注意,必须使用备用pip来匹配备用python。文件中给出了完整的解释。
例如在openSUSE上(标准python版本3.6,备用安装版本3.8):
uqjltbpv4#
我在使用gradio应用程序时遇到了同样的问题。解决方案
pip uninstall gi pip3 install pgi
对我很有效