Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with graphcut support #103

Closed
matthewdeancooper opened this issue Jun 30, 2021 · 8 comments
Closed

Issue with graphcut support #103

matthewdeancooper opened this issue Jun 30, 2021 · 8 comments

Comments

@matthewdeancooper
Copy link

matthewdeancooper commented Jun 30, 2021

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.

@loli
Copy link
Owner

loli commented Jun 30, 2021

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
Copy link
Owner

loli commented Jun 30, 2021

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

@loli loli added the bug label Jun 30, 2021
@loli loli added this to the MedPy1.0.0 milestone Jun 30, 2021
@matthewdeancooper
Copy link
Author

matthewdeancooper commented Jul 5, 2021

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
Copy link
Author

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
Copy link
Author

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

@matthewdeancooper
Copy link
Author

matthewdeancooper commented Aug 5, 2021

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.

@loli
Copy link
Owner

loli commented Feb 26, 2022

Thanks for all the work on CentOs!

@loli loli closed this as completed Feb 26, 2022
@loli loli reopened this Feb 26, 2022
@loli loli mentioned this issue Dec 15, 2023
46 tasks
@loli
Copy link
Owner

loli commented Apr 3, 2024

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

@loli loli closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants