python 如何解决Mac OS上的Pygraphviz错误?

jgwigjjp  于 2023-10-14  发布在  Python
关注(0)|答案(4)|浏览(154)

我在安装pygraphviz时遇到问题,我正在macOS Monterey上使用Anaconda。
我已经在水蟒上用过graphviz了。我一样

brew install graphviz

然后

pip install pygraphviz

但我一直得到这个错误:

Collecting pygraphviz
  Using cached pygraphviz-1.7.zip (118 kB)
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/susiekim4/opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"'; __file__='"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-wheel-4fuwg_2b
       cwd: /private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/
  Complete output (71 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.8
  creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  copying pygraphviz/scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  copying pygraphviz/graphviz.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  copying pygraphviz/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  copying pygraphviz/agraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  copying pygraphviz/testing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_close.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
  running egg_info
  writing pygraphviz.egg-info/PKG-INFO
  writing dependency_links to pygraphviz.egg-info/dependency_links.txt
  writing top-level names to pygraphviz.egg-info/top_level.txt
  reading manifest file 'pygraphviz.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  warning: no files found matching '*.png' under directory 'doc'
  warning: no files found matching '*.txt' under directory 'doc'
  warning: no files found matching '*.css' under directory 'doc'
  warning: no previously-included files matching '*~' found anywhere in distribution
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  warning: no previously-included files matching '.svn' found anywhere in distribution
  no previously-included directories found matching 'doc/build'
  writing manifest file 'pygraphviz.egg-info/SOURCES.txt'
  copying pygraphviz/graphviz.i -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
  running build_ext
  building 'pygraphviz._graphviz' extension
  creating build/temp.macosx-10.9-x86_64-3.8
  creating build/temp.macosx-10.9-x86_64-3.8/pygraphviz
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include/python3.8 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.9-x86_64-3.8/pygraphviz/graphviz_wrap.o
  pygraphviz/graphviz_wrap.c:1756:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
        0,                                    /* tp_print */
        ^
  /Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
      Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      ^
  /Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
  #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                       ^
  pygraphviz/graphviz_wrap.c:1923:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
        0,                                    /* tp_print */
        ^
  /Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
      Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
      ^
  /Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
  #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                       ^
  pygraphviz/graphviz_wrap.c:2711:10: fatal error: 'graphviz/cgraph.h' file not found
  #include "graphviz/cgraph.h"
           ^~~~~~~~~~~~~~~~~~~
  2 warnings and 1 error generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pygraphviz
  Running setup.py clean for pygraphviz
Failed to build pygraphviz
Installing collected packages: pygraphviz
    Running setup.py install for pygraphviz ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/susiekim4/opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"'; __file__='"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/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/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-record-pnja99aw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/susiekim4/opt/anaconda3/include/python3.8/pygraphviz
         cwd: /private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/
    Complete output (71 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.8
    creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    copying pygraphviz/scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    copying pygraphviz/graphviz.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    copying pygraphviz/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    copying pygraphviz/agraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    copying pygraphviz/testing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    creating build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_unicode.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_scraper.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_readwrite.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_string.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_html.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_node_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_drawing.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_subgraph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_close.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_edge_attributes.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_clear.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_layout.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_attribute_defaults.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    copying pygraphviz/tests/test_graph.py -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz/tests
    running egg_info
    writing pygraphviz.egg-info/PKG-INFO
    writing dependency_links to pygraphviz.egg-info/dependency_links.txt
    writing top-level names to pygraphviz.egg-info/top_level.txt
    reading manifest file 'pygraphviz.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching '*.png' under directory 'doc'
    warning: no files found matching '*.txt' under directory 'doc'
    warning: no files found matching '*.css' under directory 'doc'
    warning: no previously-included files matching '*~' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '.svn' found anywhere in distribution
    no previously-included directories found matching 'doc/build'
    writing manifest file 'pygraphviz.egg-info/SOURCES.txt'
    copying pygraphviz/graphviz.i -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    copying pygraphviz/graphviz_wrap.c -> build/lib.macosx-10.9-x86_64-3.8/pygraphviz
    running build_ext
    building 'pygraphviz._graphviz' extension
    creating build/temp.macosx-10.9-x86_64-3.8
    creating build/temp.macosx-10.9-x86_64-3.8/pygraphviz
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include -arch x86_64 -I/Users/susiekim4/opt/anaconda3/include/python3.8 -c pygraphviz/graphviz_wrap.c -o build/temp.macosx-10.9-x86_64-3.8/pygraphviz/graphviz_wrap.o
    pygraphviz/graphviz_wrap.c:1756:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
          0,                                    /* tp_print */
          ^
    /Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
        Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
        ^
    /Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
    #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                         ^
    pygraphviz/graphviz_wrap.c:1923:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
          0,                                    /* tp_print */
          ^
    /Users/susiekim4/opt/anaconda3/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
        Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
        ^
    /Users/susiekim4/opt/anaconda3/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
    #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                         ^
    pygraphviz/graphviz_wrap.c:2711:10: fatal error: 'graphviz/cgraph.h' file not found
    #include "graphviz/cgraph.h"
             ^~~~~~~~~~~~~~~~~~~
    2 warnings and 1 error generated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/susiekim4/opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/setup.py'"'"'; __file__='"'"'/private/var/folders/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-install-zr2twxnl/pygraphviz_e78bc2c823034812a5ffbd6ef61160d7/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/j5/z34rlnbj2l94p1hh0x_hkkjw0000gn/T/pip-record-pnja99aw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/susiekim4/opt/anaconda3/include/python3.8/pygraphviz Check the logs for full command output.

我试过pip3 installpip install cgraph和其他解决方案。
我错过了什么?

wfauudbj

wfauudbj1#

在Mac上,您必须传递安装目录的路径,以便wheel编译器可以找到graphviz头文件和库文件。具体操作如下:
使用Homebrew安装graphviz:

brew install graphviz

获取安装目录:

brew --prefix graphviz

GRAPHVIZ_DIR设置为安装位置:

export GRAPHVIZ_DIR="[INSTALL PATH HERE]"

安装graphviz,指定路径:
如果 * 使用 * pip *23.2或更高版本 *:

export GRAPHVIZ_DIR="$(brew --prefix graphviz)"
pip install pygraphviz \
    --global-option=build_ext \
    --global-option="-I$GRAPHVIZ_DIR/include" \
    --global-option="-L$GRAPHVIZ_DIR/lib"

如果使用pip的 * 早期版本 *:

export GRAPHVIZ_DIR="$(brew --prefix graphviz)"
pip install pygraphviz \
    --config-settings=--global-option=build_ext \
    --config-settings=--global-option="-I$GRAPHVIZ_DIR/include" \
    --config-settings=--global-option="-L$GRAPHVIZ_DIR/lib"

有了这些添加,包应该可以成功编译和安装:

Collecting pygraphviz
  Using cached pygraphviz-1.11.zip (120 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (pyproject.toml) ... done
  Created wheel for pygraphviz: filename=pygraphviz-1.11-cp311-cp311-macosx_13_0_arm64.whl size=100586 sha256=0d6e56168321d335706a6c6789a006b8d2831bbd32b1cd28bd8fb2238122f73b
  Stored in directory: .../pip/wheels/c8/03/73/b754941d55845a8b326f6de528bc70e65774838c76effa6d51
Successfully built pygraphviz
Installing collected packages: pygraphviz
Successfully installed pygraphviz-1.11
mwg9r5ms

mwg9r5ms2#

对我来说,它使用这个工作:

python -m pip install \
    --global-option=build_ext \
    --global-option="-I$(brew --prefix graphviz)/include/" \
    --global-option="-L$(brew --prefix graphviz)/lib/" \
    pygraphviz
5uzkadbs

5uzkadbs3#

我复制/opt/homebrew/bin/dot到/usr/local/bin/dot,重新启动visual studio代码,完成了!
指令:

sudo cp /opt/homebrew/bin/dot /usr/local/bin/dot
cxfofazt

cxfofazt4#

强烈推荐azabraoo为我工作的唯一解决方案:

pip install --global-option=build_ext --global-option="-I$(brew --prefix graphviz)/include/" --global-option="-L$(brew --prefix graphviz)/lib/" pygraphviz

相关问题