medpy icon indicating copy to clipboard operation
medpy copied to clipboard

Issue with graphcut support

Open matthewdeancooper opened this issue 4 years ago • 7 comments

I am running Ubuntu 20.04LTS.

I have installed the required packages for support

sudo apt-get install libboost-python-dev build-essential

The following install succeeds in a fresh py39 environment established via conda

pip install medpy

However, I am getting the following error

>>> import medpy.graphcut
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/matthew/etc/anaconda3/envs/py39/lib/python3.9/site-packages/medpy/graphcut/__init__.py", line 200, in <module>
    from .maxflow import GraphDouble, GraphFloat, GraphInt # this always triggers an error in Eclipse, but is right
ModuleNotFoundError: No module named 'medpy.graphcut.maxflow'

The same situation is true for a fresh py36 environment too.

matthewdeancooper avatar Jun 30 '21 05:06 matthewdeancooper

You can take a look at the logs of the installation process with:

pip install medpy --no-cache-dir --log LOG_FILE

Just remember to uninstall medpy before. And the --no-cache-dir flag is required to get pip to re-compile the medpy package from scratch.

Medpy is set up such that it will try to compile the graphcut extension. But when it fails at the task, it simply installs without it. In the logs you should see the failed compilation marked by the following lines:

2021-06-30T11:07:32,684   ***************************************************************************
2021-06-30T11:07:32,685   WARNING: The medpy.graphcut.maxflow external C++ package could not be compiled, all graphcut functionality will be disabled. You might be missing Boost.Python or some build essentials like g++.
2021-06-30T11:07:32,685   Failure information, if any, is above.
2021-06-30T11:07:32,685   I'm retrying the build without the graphcut C++ module now.
2021-06-30T11:07:32,685   ***************************************************************************

The error should be detailed in the lines just above.

One thing to look out for is to use Python 3. Ubuntu 20.04LTS still uses Python 2.7 as default, but supports Python 3. You can e.g. install medpy in a virtual environment.

Alternatively, there might be a problem with the linking of the (lib)boost_python3 lib. There are some inconsistent naming conventions around that medpy sometimes misses. At my local machine, the boost python package creates libboost_python38.so under /usr/lib/x86_64-linux-gnu, but medpy looks for a generic libboost_python3.so. This can be solved by entering the directory and creating a softlink with

sudo ln -s libboost_python38.so libboost_python3.so

Hope one of these solves your problems.

loli avatar Jun 30 '21 10:06 loli

Note to myself: Get the installation script to correctly identify the name of the shared libboost_python lib.

loli avatar Jun 30 '21 10:06 loli

You were correct that libboost_python38.so was the only file present in /usr/lib/x86_64-linux-gnu/libboost_python*

After creating the symbolic link as outlined above i managed to get the import working. It would be nice fix for the 1.0.0 release as sudo ln -s requires containerisation in HPC environments.

However, pip install medpy --no-cache-dir was not successful.

Instead, use pip install medpy --no-cache-dir --force-reinstall.

Thanks for your help.

matthewdeancooper avatar Jul 05 '21 11:07 matthewdeancooper

Does medpy currently support CentOS 7?

I have installed the deps

yum install -y \
        gcc \
        gcc-c++ \
        kernel-devel \
        make \
        boost \
        boost-devel \
        boost-doc \
        boost-python \

And created a symbolic link as follows

ln -s /lib64/libboost_python.so /lib64/libboost_python3.so

Installing medpy in a conda py38 environment

pip install --upgrade pip && pip install --no-cache-dir --force-reinstall \
        medpy

I receive the following output after installation

>>> import medpy.graphcut
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.8/site-packages/medpy/graphcut/__init__.py", line 200, in <module>
    from .maxflow import GraphDouble, GraphFloat, GraphInt # this always triggers an error in Eclipse, but is right
ImportError: /opt/conda/lib/python3.8/site-packages/medpy/graphcut/maxflow.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE

Again, I appreciate your help.

matthewdeancooper avatar Aug 05 '21 03:08 matthewdeancooper

Ah, im suspecting that the CentOS install only included python2.so files for boost.

matthewdeancooper avatar Aug 05 '21 03:08 matthewdeancooper

For others looking for a CentOS 7 solution. Yum does not include the python3 libs by default. You will need to add the epel repo to access them.

yum install epel-release -y \
    && yum repolist -y \
    && yum install -y \
        gcc \
        gcc-c++ \
        kernel-devel \
        make \
        boost*

This includes the correct file /lib64/libboost_python3.so that is discoverable by medpy without the need for a symbolic link.

matthewdeancooper avatar Aug 05 '21 04:08 matthewdeancooper

Thanks for all the work on CentOs!

loli avatar Feb 26 '22 09:02 loli

Improved graphcut installation help now in documentation: http://loli.github.io/medpy/installation/graphcutsupport.html

loli avatar Apr 03 '24 18:04 loli