Repository: GPflow/GPflow

Issue:
error while importing GPflow 
I can not import GPflow. I instelled it by  `python setup.py develop` on virtualenv. Tests are also failing to run.
### Import error

```
In [2]: import GPflow
---------------------------------------------------------------------------
NotFoundError                             Traceback (most recent call last)
<ipython-input-2-d5391a053bbd> in <module>()
----> 1 import GPflow

/home/me/<...>/GPflow/GPflow/__init__.py in <module>()
     15 
     16 # flake8: noqa
---> 17 from . import likelihoods, kernels, param, model, gpmc, sgpmc, priors, gpr, svgp, vgp, sgpr
     18 from ._version import __version__

/home/me/<...>/GPflow/GPflow/likelihoods.py in <module>()
     17 import tensorflow as tf
     18 import numpy as np
---> 19 from .param import Parameterized, Param
     20 from . import transforms
     21 hermgauss = np.polynomial.hermite.hermgauss

/home/me/<...>/GPflow/GPflow/param.py in <module>()
     17 import pandas as pd
     18 import tensorflow as tf
---> 19 from . import transforms
     20 from contextlib import contextmanager
     21 from functools import wraps

/home/me/<...>/GPflow/GPflow/transforms.py in <module>()
     16 import numpy as np
     17 import tensorflow as tf
---> 18 import GPflow.tf_hacks as tfh
     19 
     20 

/home/me/<...>/GPflow/GPflow/tf_hacks.py in <module>()
     28 
     29 
---> 30 _custom_op_module = tf.load_op_library(os.path.join(os.path.dirname(__file__), 'tfops', 'matpackops.so'))
     31 vec_to_tri = _custom_op_module.vec_to_tri
     32 tri_to_vec = _custom_op_module.tri_to_vec

/home/me/.virtualenvs/tf_0_10/lib/python2.7/site-packages/tensorflow/python/framework/load_library.pyc in load_op_library(library_filename)
     73           return _OP_LIBRARY_MAP[library_filename]
     74       # pylint: disable=protected-access
---> 75       raise errors._make_specific_exception(None, None, error_msg, error_code)
     76       # pylint: enable=protected-access
     77   finally:

NotFoundError: GPflow/tfops/matpackops.so: undefined symbol: _ZN10tensorflow7strings6StrCatB5cxx11ERKNS0_8AlphaNumE

```
### Test error

```
running test
running egg_info
writing requirements to GPflow.egg-info/requires.txt
writing GPflow.egg-info/PKG-INFO
writing top-level names to GPflow.egg-info/top_level.txt
writing dependency_links to GPflow.egg-info/dependency_links.txt
reading manifest file 'GPflow.egg-info/SOURCES.txt'
writing manifest file 'GPflow.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 50, in <module>
    'Topic :: Scientific/Engineering :: Artificial Intelligence']
  File "/usr/lib64/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib64/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/me/.virtualenvs/tf_0_10/lib/python2.7/site-packages/setuptools/command/test.py", line 172, in run
    self.run_tests()
  File "/home/me/.virtualenvs/tf_0_10/lib/python2.7/site-packages/setuptools/command/test.py", line 193, in run_tests
    testRunner=self._resolve_as_ep(self.test_runner),
  File "/usr/lib64/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib64/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/lib64/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/lib64/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib64/python2.7/unittest/loader.py", line 103, in loadTestsFromName
    return self.loadTestsFromModule(obj)
  File "/home/me/.virtualenvs/tf_0_10/lib/python2.7/site-packages/setuptools/command/test.py", line 40, in loadTestsFromModule
    tests.append(self.loadTestsFromName(submodule))
  File "/usr/lib64/python2.7/unittest/loader.py", line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_variational'

```



Discussion:
Hi @BPie , thanks for the bug report. 

Could you let us know:
1) which version of tensorflow are you using?
2) which version of python?
3) which os?

and we'll do our best to replicate and fix. 

Hi @jameshensman , my environment looks like described below:
tf 0.10
Python 2.7.11
Fedora 23

### pip freeze (virtualenv)

```
pip freeze                
funcsigs==1.0.2
-e git+https://github.com/GPflow/GPflow.git@67cfd5d2d25a3a90e1f873fbac0b05c025d04a1d#egg=GPflow
linecache2==1.0.0
mock==2.0.0
numpy==1.11.1
pbr==1.10.0
protobuf==3.0.0b2
scipy==0.18.0
six==1.10.0
tensorflow==0.10.0rc0
traceback2==1.4.0
unittest2==1.1.0
```

Great, thanks @BPie . 

I'm still not sure where the problem is, but it looks like the binaries are not getting linked correctly. This might be because tensorflow is in an unusual path in fedora? We should be finding it automatically though. 

Could you report the outputs of these, please?

``` bash
python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())'
```

and

``` bash
git clone git@github.com:GPflow/GPflow.git
cd GPflow
python setup.py build
```

Much appreciated.

oop and `gcc --version`, please.

tf is installd by pip inside virtualenv, so it is not in a default place for fedora.

### tf installation place (virtualenv)

```
❯❯❯ python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())'                         
/home/me/.virtualenvs/tf_0_10/lib/python2.7/site-packages/tensorflow/include
```

### installing GPflow

```
❯❯❯ git clone https://github.com/GPflow/GPflow.git                                                ⏎
Cloning into 'GPflow'...
remote: Counting objects: 3458, done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 3458 (delta 23), reused 0 (delta 0), pack-reused 3409
Receiving objects: 100% (3458/3458), 12.32 MiB | 1.44 MiB/s, done.
Resolving deltas: 100% (2391/2391), done.
Checking connectivity... done.

❯❯❯ cd GPflow

❯❯❯ git status                                                                                          
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

❯❯❯ python setup.py build                                                                               
running build
running build_py
creating build
creating build/lib
creating build/lib/GPflow
copying GPflow/__init__.py -> build/lib/GPflow
copying GPflow/svgp.py -> build/lib/GPflow
copying GPflow/transforms.py -> build/lib/GPflow
copying GPflow/param.py -> build/lib/GPflow
copying GPflow/_version.py -> build/lib/GPflow
copying GPflow/priors.py -> build/lib/GPflow
copying GPflow/gpmc.py -> build/lib/GPflow
copying GPflow/model.py -> build/lib/GPflow
copying GPflow/sgpmc.py -> build/lib/GPflow
copying GPflow/likelihoods.py -> build/lib/GPflow
copying GPflow/conditionals.py -> build/lib/GPflow
copying GPflow/gpr.py -> build/lib/GPflow
copying GPflow/kullback_leiblers.py -> build/lib/GPflow
copying GPflow/vgp.py -> build/lib/GPflow
copying GPflow/densities.py -> build/lib/GPflow
copying GPflow/kernels.py -> build/lib/GPflow
copying GPflow/tf_hacks.py -> build/lib/GPflow
copying GPflow/hmc.py -> build/lib/GPflow
copying GPflow/sgpr.py -> build/lib/GPflow
copying GPflow/mean_functions.py -> build/lib/GPflow
running egg_info
creating GPflow.egg-info
writing requirements to GPflow.egg-info/requires.txt
writing GPflow.egg-info/PKG-INFO
writing top-level names to GPflow.egg-info/top_level.txt
writing dependency_links to GPflow.egg-info/dependency_links.txt
writing manifest file 'GPflow.egg-info/SOURCES.txt'
reading manifest file 'GPflow.egg-info/SOURCES.txt'
writing manifest file 'GPflow.egg-info/SOURCES.txt'
```

### gcc

```
❯❯❯ gcc --version     
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

This time python complained about not having pandas while importing GPflow (strange that it did not complain the last time).

Thanks! I think the problem is that the tensorflow binary is compiled with gcc 4, you're using gcc5. There's a note on the 'adding an op page': 

https://www.tensorflow.org/versions/r0.10/how_tos/adding_an_op/index.html

> Note on gcc version 5: gcc5 uses the new C++ ABI. The binary pip packages available on the TensorFlow website are built with gcc4 that uses the older ABI. If you compile your op library with gcc5, add -D_GLIBCXX_USE_CXX11_ABI=0 to the command line to make the library compatible with the older abi.

So I guess the fix is to add that line to setup.py, where we're compiling the additional ops. We'd need to detect gcc4/5, and then optionally add that line to the compile statement. 

thanks @jameshensman , adding  `-D_GLIBCXX_USE_CXX11_ABI=0` solved the issue.

great!

I'm going to leave this bug report open until it's fixed in GPflow's setup.py

Thanks again for your input.

Thanks for the help :)

this  checks the version in my case 

```
import re
int(re.search('\d+.', os.popen("gcc --version").read()).group()[0])
```

But I don't know if output of `gcc --version` is always the same

Thanks -  that will work on linux, but on osx gcc is actually clang, so gcc--version spits out all kinds of garbage... your command returns 7 on my macbook!


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -23,6 +23,10 @@
 if sys.platform == "darwin":
     # Additional command for Macs, as instructed by the TensorFlow docs
     compile_command += " -undefined dynamic_lookup"
+elif sys.platform.startswith("linux"):
+    gcc_version = int(re.search('\d+.', os.popen("gcc --version").read()).group()[0])
+    if gcc_version == 5:
+        compile_command += " -D_GLIBCXX_USE_CXX11_ABI=0"
 os.system(compile_command)
 
 setup(name='GPflow',


Test patch: