通过pip3安装pycairo时遇到问题
Trouble installing pycairo through pip3
我一直在尝试在 MacO 上使用 pip3 安装 pycairo,但每当您尝试这样做时,都会出现此错误:
pip3 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: Complete output from command /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/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 /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-record-egwlnpkb/install-record.txt --single-version-externally-managed --compile:
ERROR: running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.7
creating build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/__init__.pyi -> build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/py.typed -> build/lib.macosx-10.9-x86_64-3.7/cairo
running build_ext
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1.
----------------------------------------
ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/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 /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-record-egwlnpkb/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/pycairo/
我已经使用 brew 安装了 cairo 和 pkg-config。
更新,我确实使用以下命令
设置了PKG_CONFIG_PATH的路径
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.2.1/lib/pkgconfig/
然后使用 pip3 安装 pycairo 就可以了。唯一就是即使现在安装了python3也没有找到pycairo
python3
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pycairo'
我用 brew 安装了以下软件
brew list
aom jpeg p11-kit
atk lame pango
cairo leptonica pcre
ffmpeg libass pixman
flac libbluray pkg-config
fontconfig libevent python
freetype libffi readline
frei0r libogg rtmpdump
fribidi libpng rubberband
gdbm libsamplerate sdl2
gdk-pixbuf libsndfile snappy
gettext libsoxr speex
ghostscript libtasn1 sqlite
giflib libtiff tesseract
glew libunistring theora
glib libvorbis unbound
gmp libvpx webp
gnutls little-cms2 x264
graphite2 nettle x265
gtk+ opencore-amr xvid
harfbuzz openjpeg xz
hicolor-icon-theme openssl
icu4c opus
这是我的 pip3 列表
astroid 2.2.5
cairocffi 1.0.2
cffi 1.12.3
isort 4.3.16
lazy-object-proxy 1.3.1
mccabe 0.6.1
opencv-python 3.4.2.17
pip 19.1
pycairo 1.18.1 #it seems like it's installed but it doesn't recognize it whenever I try to import it
pycparser 2.19
pylint 2.3.1
setuptools 40.8.0
typed-ast 1.3.1
wrapt 1.11.1
您在 pip3
输出中有答案:
Package 'libffi', required by 'gobject-2.0', not found
在 macOS 上,brew install libffi
应该可以。
(此外,当然,将任何东西安装到系统 Python 中,而不是在 virtualenv 中通常是个坏主意。)
有同样的问题。
解决方案:
通过 brew 安装 python3 和 libffi。仅在安装 cairo 之前执行此操作:
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
现在继续 运行 pip:
pip3 install --user pycairo
此后一切正常。
在 macOS 10.14.6 上测试,python 3.7.4 通过 brew 安装,libffi 3.2.1 通过 brew 安装。
我一直在尝试在 MacO 上使用 pip3 安装 pycairo,但每当您尝试这样做时,都会出现此错误:
pip3 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: Complete output from command /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/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 /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-record-egwlnpkb/install-record.txt --single-version-externally-managed --compile:
ERROR: running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.7
creating build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/__init__.pyi -> build/lib.macosx-10.9-x86_64-3.7/cairo
copying cairo/py.typed -> build/lib.macosx-10.9-x86_64-3.7/cairo
running build_ext
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.13.1']' returned non-zero exit status 1.
----------------------------------------
ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/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 /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-record-egwlnpkb/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/0w/2v91jtp54jl7b4cdqrhk_96h0000gn/T/pip-install-uiqmlfkz/pycairo/
我已经使用 brew 安装了 cairo 和 pkg-config。
更新,我确实使用以下命令
设置了PKG_CONFIG_PATH的路径export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.2.1/lib/pkgconfig/
然后使用 pip3 安装 pycairo 就可以了。唯一就是即使现在安装了python3也没有找到pycairo
python3
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pycairo'
我用 brew 安装了以下软件
brew list
aom jpeg p11-kit
atk lame pango
cairo leptonica pcre
ffmpeg libass pixman
flac libbluray pkg-config
fontconfig libevent python
freetype libffi readline
frei0r libogg rtmpdump
fribidi libpng rubberband
gdbm libsamplerate sdl2
gdk-pixbuf libsndfile snappy
gettext libsoxr speex
ghostscript libtasn1 sqlite
giflib libtiff tesseract
glew libunistring theora
glib libvorbis unbound
gmp libvpx webp
gnutls little-cms2 x264
graphite2 nettle x265
gtk+ opencore-amr xvid
harfbuzz openjpeg xz
hicolor-icon-theme openssl
icu4c opus
这是我的 pip3 列表
astroid 2.2.5
cairocffi 1.0.2
cffi 1.12.3
isort 4.3.16
lazy-object-proxy 1.3.1
mccabe 0.6.1
opencv-python 3.4.2.17
pip 19.1
pycairo 1.18.1 #it seems like it's installed but it doesn't recognize it whenever I try to import it
pycparser 2.19
pylint 2.3.1
setuptools 40.8.0
typed-ast 1.3.1
wrapt 1.11.1
您在 pip3
输出中有答案:
Package 'libffi', required by 'gobject-2.0', not found
在 macOS 上,brew install libffi
应该可以。
(此外,当然,将任何东西安装到系统 Python 中,而不是在 virtualenv 中通常是个坏主意。)
有同样的问题。
解决方案:
通过 brew 安装 python3 和 libffi。仅在安装 cairo 之前执行此操作:
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
现在继续 运行 pip:
pip3 install --user pycairo
此后一切正常。
在 macOS 10.14.6 上测试,python 3.7.4 通过 brew 安装,libffi 3.2.1 通过 brew 安装。