Problems installing graph-tool with homebrew and python3 on macOS Sierra

Hey,

I am getting the following errors:

Kimons-MacBook-Pro:graph-tool-2.25 kimonfountoulakis$ brew instal -s
--with-python3 graph-tool
==> Installing graph-tool from homebrew/science
==> Installing dependencies for homebrew/science/graph-tool: matplotlib,
py2cairo, libcroco, librsvg, gnome-icon-theme, pygobject3
==> Installing homebrew/science/graph-tool dependency: matplotlib
==> Downloading
https://files.pythonhosted.org/packages/f5/f0/9da3ef24ea7eb0ccd12430a261b66eca36b924aeef06e17147f9f9d7d310/matplotlib-2.0.2.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib-2.0.2.tar.gz
==> Downloading
https://files.pythonhosted.org/packages/dc/8c/7c9869454bdc53e72fb87ace63eac39336879eef6f2bf96e946edbf03e90/setuptools-33.1.1.zip
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--setuptools-33.1.1.zip
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/c2/4b/137dea450d6e1e3d474e1d873cd1d4f7d3beed7e0dc973b06e8e10d32488/cycler-0.10.0.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--Cycler-0.10.0.tar.gz
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/c5/60/6ac26ad05857c601308d8fb9e87fa36d0ebf889423f47c3502ef034365db/functools32-3.2.3-2.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--functools32-3.2.3-2.tar.gz
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/38/bb/bf325351dd8ab6eb3c3b7c07c3978f38b2103e2ab48d59726916907cd6fb/pyparsing-2.1.10.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--pyparsing-2.1.10.tar.gz
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/51/fc/39a3fbde6864942e8bb24c93663734b74e281b984d1b8c4f95d64b0c21f6/python-dateutil-2.6.0.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--python-dateutil-2.6.0.tar.gz
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/d0/e1/aca6ef73a7bd322a7fc73fd99631ee3454d4fc67dc2bee463e2adf6bb3d3/pytz-2016.10.tar.bz2
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--pytz-2016.10.tar.bz2
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/b3/b2/238e2590826bfdd113244a40d9d3eb26918bd798fc187e2360a8367068db/six-1.10.0.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--six-1.10.0.tar.gz
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> Downloading
https://files.pythonhosted.org/packages/b8/2f/49e53b0d0e94611a2dc624a1ad24d41b6d94d0f1b0a078443407ea2214c2/subprocess32-3.2.7.tar.gz
Already downloaded:
/Users/kimonfountoulakis/Library/Caches/Homebrew/matplotlib--subprocess32-3.2.7.tar.gz
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2/libexec
--single-version-externally-managed --record=installed.txt
==> python -c import setuptools... --no-user-cfg install
--prefix=/usr/local/Cellar/matplotlib/2.0.2
--single-version-externally-managed --record=installed.txt
Last 15 lines from
/Users/kimonfountoulakis/Library/Logs/Homebrew/matplotlib/09.python:
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:322:9:
error: no member named 'islessequal' in the global namespace
using ::islessequal;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:323:9:
error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:324:9:
error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:325:9:
error: no member named 'isunordered' in the global namespace
using ::isunordered;
      ~~^
13 errors generated.
error: command 'clang' failed with exit status 1

READ THIS: https://docs.brew.sh/Troubleshooting.html

/usr/local/Homebrew/Library/Homebrew/utils/github.rb:210:in
`raise_api_error': GitHub (GitHub::AuthenticationFailedError)
The GitHub credentials in the macOS keychain may be invalid.
Clear them with:
  printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain
erase
Or create a personal access token:

https://github.com/settings/tokens/new?scopes=gist,public_repo&description=Homebrew
and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token"
  from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:178:in `open'
  from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:278:in `search'
  from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:225:in
`search_issues'
  from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:238:in
`issues_for_formula'
  from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:369:in
`fetch_issues'
  from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:365:in `issues'
  from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:419:in `dump'
  from /usr/local/Homebrew/Library/Homebrew/brew.rb:135:in `rescue in <main>'
  from /usr/local/Homebrew/Library/Homebrew/brew.rb:30:in `<main>'

Any ideas?

I also tried python2.7 installed from Homebrew and I get the following:

Kimons-MacBook-Pro:graph-tool-2.25 kimonfountoulakis$ python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import graph_tool

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/graph_tool/__init__.py",
line 104, in <module>
    import numpy
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py",
line 142, in <module>
    from . import add_newdocs
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py",
line 13, in <module>
    from numpy.lib import add_newdoc
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py",
line 8, in <module>
    from .type_check import *
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py",
line 11, in <module>
    import numpy.core.numeric as _nx
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py",
line 33, in <module>
    from . import _internal # for freeze programs
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_internal.py",
line 14, in <module>
    import ctypes
  File
"/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py",
line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError:
dlopen(/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so,
2): Symbol not found: __PySlice_AdjustIndices
  Referenced from:
/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so
  Expected in: flat namespace
in
/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so

Please report homebrew problems to their issue tracker:
https://github.com/Homebrew/brew/issues

Note that the problem occurs when installing matplotlib, not graph-tool...

Can you import numpy directly without any problems?

Yes I can.

Ok, well, this is still obviously a problem with library/compiler mismatch,
so you should report it to the homebrew people.

Sure, thanks!

Is there a way to install graph-tool in Sierra? Homebrew fails to install
properly for both python2 and python3; see the above posts.

I tried to install from source using

./configure PYTHON=python2 (executed successfully)
make (crashed after 10 min or so with the following error)

Kimons-MacBook-Pro:graph-tool-2.25 kimonfountoulakis$ make
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive
Making all in src
Making all in graph
Making all in centrality
make[4]: Nothing to be done for `all'.
Making all in clustering
make[4]: Nothing to be done for `all'.
Making all in correlations
make[4]: Nothing to be done for `all'.
Making all in draw
make[4]: Nothing to be done for `all'.
Making all in flow
make[4]: Nothing to be done for `all'.
Making all in generation
make[4]: Nothing to be done for `all'.
Making all in inference
  CXX blockmodel/graph_blockmodel.lo
In file included from blockmodel/graph_blockmodel.cc:24:
In file included from blockmodel/graph_blockmodel.hh:28:
../../../src/graph/openmp_lock.hh:52:75: error: 'lock' is a private member
of 'openmp_mutex'
    explicit scoped_lock(openmp_mutex& m) : _mut(m), _locked(true) {
_mut.lock(); }
                                                                          ^
../../../src/graph/openmp_lock.hh:44:9: note: implicitly declared private
here
   void lock() {}
        ^
../../../src/graph/openmp_lock.hh:54:63: error: 'unlock' is a private member
of 'openmp_mutex'
    void unlock() { if(!_locked) return; _locked=false; _mut.unlock(); }
                                                              ^
../../../src/graph/openmp_lock.hh:45:9: note: implicitly declared private
here
   void unlock() {}
        ^
../../../src/graph/openmp_lock.hh:55:47: error: 'lock' is a private member
of 'openmp_mutex'
    void lock() { if(_locked) return; _mut.lock(); _locked=true; }
                                              ^
../../../src/graph/openmp_lock.hh:44:9: note: implicitly declared private
here
   void lock() {}
        ^
In file included from blockmodel/graph_blockmodel.cc:24:
blockmodel/graph_blockmodel.hh:300:31: warning: unknown attribute
'fallthrough' ignored [-Wunknown-attributes]
                            [[gnu::fallthrough]];
                              ^
blockmodel/graph_blockmodel.hh:667:23: warning: unknown attribute
'fallthrough' ignored [-Wunknown-attributes]
                    [[gnu::fallthrough]];
                      ^
blockmodel/graph_blockmodel.hh:760:23: warning: unknown attribute
'fallthrough' ignored [-Wunknown-attributes]
                    [[gnu::fallthrough]];
                      ^
3 warnings and 3 errors generated.
make[4]: *** [blockmodel/graph_blockmodel.lo] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Please let me know if there is any workaround. I really want to use
graph-tool in my work.

Hi Kimon,

I have had similar issues installing graph-tool on the mac. Currently I have
it up and running (with a slight gtk+ problem when trying to export animated
graphs), but this might be an individual success. However, below I send you
the step by step solution that I came up with. At my end this worked at
least. Please let me know if it works for you as well.

Best,
m

Step by step instructions on how to install a working copy of graph-tool on
OS X (tested with High Sierra) with Python 3.X and OpenMP support.

1) Remove all already installed dependencies (Check with brew info
graph-tool)

2) Install llvm, Automarke und libtool:
  brew install llvm
  brew install automake
  brew install libtool

3) Add llvm to environment variables:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile

4) Reinitialize ENV:
  source ~/.bash_profile

5) Check if the correct clang is called (not Apple clang):
  clang --version

6) Install all python3 and all dependencies
  brew install python3
  brew install pkg-config
  brew install boost
  brew install boost-python --with-python3 --without-python
  brew install cairomm
  brew install cgal
  brew install py3cairo
  brew install gnome-icon-theme
  brew install gtk+3
  brew install --force librsvg --with-gtk+3
  brew install pygobject3 --with-python3 --without-python
  brew install google-sparsehash

7) Install python packages with pip3: numpy, scipy, matplotlib
  pip3 install numpy
  pip3 install scipy
  pip3 install matplotlib

7) Clone graph-tool repository:
  git clone https://git.skewed.de/count0/graph-tool.git

8) Go to the cloned git folder

9) Set correct Python version in file configure.ac:

  AM_PATH_PYTHON([3.6]) ## Replace 2.7 by the correct version you are using

10) Run
  ./autogen.sh

11) Modify generated configure file in order to solve a nasty ldflags issue:

  Replace:

    if test -z "$PYTHON_EXTRA_LDFLAGS"; then
      PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
        conf = distutils.sysconfig.get_config_var; \
        print (conf('LINKFORSHARED'))"`

  With:

    if test -z "$PYTHON_EXTRA_LDFLAGS"; then
      PYTHON_EXTRA_LIBS=`$PYTHON-config --ldflags`

12) Run

  ./configure CC=clang CXX=clang++ LDFLAGS="-L/usr/local/opt/llvm/lib
-Wl,-rpath,/usr/local/opt/llvm/lib" CPPFLAGS="-I/usr/local/opt/llvm/include
-fopenmp"

13) Run
  make install

13 simple steps of success :-D. This worked like a charm. Thank you very
much!

Hi,

great! Happy to help. Could you be so kind to test in turn if the example
script for dynamic layouts posted here:
https://graph-tool.skewed.de/static/doc/demos/animation/animation.html#dynamic-layout

When I pass the offscreen argument to the script python crashes with a
segmentation fault. It appears to be a gtk+ error, but it would be nice, if
its an error just on my system or something that is causing problems on mac
os.

If have a few seconds I would appreciate it a lot.

All the best,
marcus

Sure, I tested it and it seems to run fine on my Mac. I hope this is helpful
for you.

Thanks. That's makes me wonder even more. The live visualization works for me
as well, but once I try to pass the offscreen argument when starting the
script it weirdly causes a segmentation fault.

Could you please open a bug report in the homebrew website so that this
could be understood and solved?

Also, please open another bug report with the installation issues ---
including your solution --- so that it can be solved for other users as well.

Best,
Tiago

Sure, I will do that.