首页 > 解决方案 > 安装 PyGObject 时出错,找不到“glib-object.h”文件

问题描述

为了使用 gstreamer,我正在尝试在 pycharm 中为 python 2.7 安装 pygobject。但是我在安装它时遇到问题。在虚拟环境中,如果我使用

pip install pygobject

然后构建失败并给我这个错误

 gi/gimodule.c:25:10: fatal error: 'glib-object.h' file not found
 #include <glib-object.h>
          ^~~~~~~~~~~~~~~
 1 error generated.
 error: command 'cc' failed with exit status 1

完整的错误日志在这里

我知道 glib 存在于我的系统上通过搜索它

find /usr -name glib-object.h

但由于某种原因,安装找不到它。我是否必须以某种方式链接它/我该怎么做?

另外我知道我可以更成功地将这个库与 python3 一起使用,但这会导致一些奇怪的系统错误,这些错误显然可以通过使用 2.7 来解决,所以我现在只是在探索。

标签: macospython-2.7gstreamerglibpygobject

解决方案


对于虚拟环境,建议PyGObject使用pipenv而不是pip.

pipenv使用或安装:MacPorts_HomeBrewpipsi

MacPorts

port install pipenv

家酿

brew install pipenv

皮普西

curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python3 - --src=git+https://github.com/mitsuhiko/pipsi.git\#egg=pipsi
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
pipsi install pew
pipsi install pipenv

安装完成后,您pipenv应该能够将包添加到您的虚拟环境中:

pipenv install pygobject

↳ PyGObject :创建开发环境


推荐阅读