适用于 Linux Mint 18.3 32 位和 Python 3.5.2 以及 Python3 虚拟环境。
我在安装 Python 3 的notify-send时遇到问题。目标是在“通知气泡”ala 中显示文本:
我已经有一个 BASH 脚本可以满足我的要求。我希望直接在 Python3 中复制它,而不是求助于调用 BASH 的 notify-send 命令行实例的子进程。
我为 Python 3 虚拟环境创建了一个文件夹,在该文件夹中用于
python3 -m venv gui_experiments
创建虚拟环境,然后用于source env/gui_experiments/activate
激活该 venv。收到表征活跃 venv 的提示...在那个虚拟环境中,pip通知我应该升级 pip。升级后的版本已经存在于虚拟环境之外,但不在其中。在 venv 中,我尝试使用 pip 建议的命令行 --
sudo -H pip install --upgrade pip
-- pip 告诉我最新版本已经安装。为了打破upgrade->already-installed循环,我改为python3 -m pip3 install --upgrade pip3
强制 pip 升级到版本 19.3.1(截至当前日期)。pip search notify-send | grep ^notify-send
返回:通知发送 (0.0.13)
键入
sudo -H python3 -m pip install notify-send
. 冗长的错误消息==
rbv@rbv-F80Q ~/PythonLessons/gui_experiments $ sudo -H python3 -m pip install notify-send
Collecting notify-send
Using cached https://files.pythonhosted.org/packages/d1/e7/e495fda6524db0c59f3a4db05e3a54b96eae9afe4436d921dda3a7cb60ab/notify_send-0.0.13-py3-none-any.whl
Collecting pycairo>=1.18.1; sys_platform == "linux"
Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Collecting PyGObject>=3.34.0; sys_platform == "linux"
Using cached https://files.pythonhosted.org/packages/46/8a/b183f3edc812d4d28c8b671a922b5bc2863be5d38c56b3ad9155815e78dd/PyGObject-3.34.0.tar.gz
Installing build dependencies ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 /usr/local/lib/python3.5/dist-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-oxsfyhvu/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel pycairo
cwd: None
Complete output (30 lines):
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/6a/9a/50fadfd53ec909e4399b67c74cc7f4e883488035cfcdb90b685758fa8b34/setuptools-41.4.0-py2.py3-none-any.whl
Collecting wheel
Using cached https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl
Collecting pycairo
Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Installing collected packages: setuptools, wheel, pycairo
Running setup.py install for pycairo: started
Running setup.py install for pycairo: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x0kren5a/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x0kren5a/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-h73tgq7k/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-oxsfyhvu/overlay --compile
cwd: /tmp/pip-install-x0kren5a/pycairo/
Complete output (15 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-i686-3.5
creating build/lib.linux-i686-3.5/cairo
copying cairo/__init__.py -> build/lib.linux-i686-3.5/cairo
copying cairo/__init__.pyi -> build/lib.linux-i686-3.5/cairo
copying cairo/py.typed -> build/lib.linux-i686-3.5/cairo
running build_ext
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x0kren5a/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x0kren5a/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-h73tgq7k/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-oxsfyhvu/overlay --compile Check the logs for full command output.
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/local/lib/python3.5/dist-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-oxsfyhvu/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel pycairo Check the logs for full command output.
(gui_experiments)
rbv@rbv-F80Q ~/PythonLessons/gui_experiments $
- 看起来pycairo可能是问题所在。但是突触列出了已安装的 python3-cairo。所以我尝试了
sudo -H pip install pycairo
。错误信息 ==
Collecting pycairo
Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Installing collected packages: pycairo
Running setup.py install for pycairo ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-t3zwxfq6/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-t3zwxfq6/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-8mfgxfm6/install-record.txt --single-version-externally-managed --compile
cwd: /tmp/pip-install-t3zwxfq6/pycairo/
Complete output (15 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-i686-3.5
creating build/lib.linux-i686-3.5/cairo
copying cairo/__init__.py -> build/lib.linux-i686-3.5/cairo
copying cairo/__init__.pyi -> build/lib.linux-i686-3.5/cairo
copying cairo/py.typed -> build/lib.linux-i686-3.5/cairo
running build_ext
Package cairo was not found in the pkg-config search path.
Perhaps you should add the directory containing `cairo.pc'
to the PKG_CONFIG_PATH environment variable
No package 'cairo' found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-t3zwxfq6/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-t3zwxfq6/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-8mfgxfm6/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
- 尝试在停用虚拟环境并更改到其他目录后重复这些步骤。同样的问题。
在这一点上,我很难过。我不明白一些错误消息(例如,也许您应该添加包含 `cairo.pc' 的目录)。
python3 -m
在使用 pip 或安装库时,我从未遇到过这么多困难或冗长的错误消息。
我想知道问题是否出现是因为我运行的是 32 位 Linux?