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

no module named medpy.graphcut.maxflow #20

Closed
sssomani opened this issue Jun 9, 2016 · 8 comments
Closed

no module named medpy.graphcut.maxflow #20

sssomani opened this issue Jun 9, 2016 · 8 comments

Comments

@sssomani
Copy link

sssomani commented Jun 9, 2016

I just finished installing medpy (Release-0.3.0) in my Python library, but I'm running into a few issues.

What works:
medpy's io module (load, header)

What gives me problems:
medpy.graphcut

When I try and call medpy.graphcut, I run into the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/<myusername>/medpy/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: No module named 'medpy.graphcut.maxflow'

However, there's one major thing wrong with this error, which is that the directory it's referencing is where I cloned the package using git, NOT the package library where it was supposed to install the package. If I drop the 'maxflow.py' file into that folder (along with the .so file, which it subsequently requests after an error from running the same import function again), I get another error saying the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/<myusername>/medpy/medpy/graphcut/__init__.py", line 206, in <module>
    import energy_label
ImportError: No module named 'energy_label'

Could you please assist me in this matter?

Thanks!

@loli
Copy link
Owner

loli commented Jun 10, 2016

Mhh... since you found the .so file, the graphcut module compiled correctly. Why its not in the right location, I can't figure out right now (no access to my dev PC). Could you tell me with what command you installed MedPy? In develop mode? To user or system-wide library?

The follow up error seems to indicate that enery_label.py is missing. Can you find the file in the directory? But again, the search path seems to be the git clone, rather than the library path, which is strange.

Its unlikely, but from which folder are you trying to load MedPy? Its not /Users/<myusername>/medpy/ or a folder under this, is it? In such a case, the local python structure could shadow the global MedPy installation.

Please let me know the details and I'll try to help ypu further.

In general, the MedPy versions in the repository can be unstable and contain bugs. If you want to be on the save side, MedPy 0.2.2 is your right choice, although that version lacks much of the functionality found in the branch leading to the 0.3.0 release (whenever I find the time).

Best,
loli

@sssomani
Copy link
Author

For sure!

I installed MedPy using 'git clone...', and then 'python setup.py install' to my system-wide package directory ("//anaconda/lib").

Yes, I can find the 'energy_label.py' in the directory (both in the git clone directory and the installed package directory).

I'm loading MedPy from my 'anaconda/lib/python3.5/site-packages' directory.

With MedPy 0.2.2, I was still getting the same 'energy_label.py' problem :(

Hope some of this information helps! Happy to share anything else you may need.

@loli
Copy link
Owner

loli commented Jun 13, 2016

I've looked into the matter and it seems to be largely a Python3 associated problem.

You might try to change the includes in medpy/graphcut/__init__.py to import .energy_label.py. But I won't promise anything.

MedPy has been designed for Python2, not for for Python3. Most parts should be portable, but some are not. There are many issues connected with the version upgrade.

During my testing right now, I e.g. figured out that the compilation of the maxflow module is done with libboost_python2 instead of libboost_python3 (whyever). Hence even if you manage to fix the import, it might not work!

I would suggest that you switch your anaconda to python2.7 (which should be easy, according to their page) and then install MedPy (whichever version you want) again. This will hopefully solve all your problems.

@loli loli added this to the Python 3 compatible version milestone Jun 13, 2016
@loli loli self-assigned this Jun 13, 2016
@loli
Copy link
Owner

loli commented Jun 13, 2016

Notes to myself

Beside the import (@see here) there seems to be a libboost issue when compiling maxflow

Libboost and Python3 + Python2 problem
@see here
Compiling works with:
g++ maxflow.cpp wrapper.cpp graph.cpp -I/usr/include/python3.4m/ -I/usr/include/boost/ -lboost_python-py34 -lpython3.4m -o maxflow.so -shared -fPIC
Should be:
g++ maxflow.cpp wrapper.cpp graph.cpp -I/usr/include/python3.4m/ -I/usr/include/boost/ -lboost_python3 -lpython3.4m -o maxflow.so -shared -fPIC
And MedPy currently uses something like:
g++ maxflow.cpp wrapper.cpp graph.cpp -I/usr/include/python/ -I/usr/include/boost/ -lboost_python -lpython -o maxflow.so -shared -fPIC
which links against Python2, it seems.

@loli
Copy link
Owner

loli commented Sep 14, 2017

The setup.py produces currently

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -I/usr/include/python3.5m -I/home/loli/Workspace/python/medpy_release/python3/envp3/include/python3.5m -c lib/maxflow/src/maxflow.cpp -o build/temp.linux-x86_64-3.5/lib/maxflow/src/maxflow.o -O0

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -I/usr/include/python3.5m -I/home/loli/Workspace/python/medpy_release/python3/envp3/include/python3.5m -c lib/maxflow/src/wrapper.cpp -o build/temp.linux-x86_64-3.5/lib/maxflow/src/wrapper.o -O0

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DMAJOR_VERSION=0 -DMINOR_VERSION=1 -I/usr/include/python3.5m -I/home/loli/Workspace/python/medpy_release/python3/envp3/include/python3.5m -c lib/maxflow/src/graph.cpp -o build/temp.linux-x86_64-3.5/lib/maxflow/src/graph.o -O0

x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.5/lib/maxflow/src/maxflow.o build/temp.linux-x86_64-3.5/lib/maxflow/src/wrapper.o build/temp.linux-x86_64-3.5/lib/maxflow/src/graph.o -lboost_python -o build/lib.linux-x86_64-3.5/medpy/graphcut/maxflow.cpython-35m-x86_64-linux-gnu.so

in that order.

@loli
Copy link
Owner

loli commented Sep 14, 2017

The alternate version
x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 maxflow.o wrapper.o graph.o -lboost_python-py35 -o maxflow.so

works. I think I need sys.version_info.major (2/3) and sys.version_info.minor (7/5) do build this, as teh libboost_python.so invoked by -lboost_python can link to libboost_python-py27.so as well as libboost_python-py35.so.

@loli
Copy link
Owner

loli commented Sep 14, 2017

Possible solution is to replace in the setup.py

maxflow = Extension('medpy.graphcut.maxflow',
                    define_macros = [('MAJOR_VERSION', '0'),
                                     ('MINOR_VERSION', '1')],
                    sources = ['lib/maxflow/src/maxflow.cpp', 'lib/maxflow/src/wrapper.cpp', 'lib/maxflow/src/graph.cpp'],
                    libraries = ['boost_python'],
                    extra_compile_args = ['-O0'])

by

maxflow = Extension('medpy.graphcut.maxflow',
                    define_macros = [('MAJOR_VERSION', '0'),
                                     ('MINOR_VERSION', '1')],
                    sources = ['lib/maxflow/src/maxflow.cpp', 'lib/maxflow/src/wrapper.cpp', 'lib/maxflow/src/graph.cpp'],
                    libraries = ['boost_python-py' + str(sys.version_info.major) + str(sys.version_info.minor)],
                    extra_compile_args = ['-O0'])

@loli
Copy link
Owner

loli commented Sep 14, 2017

Fixed with 14c68d6 - I hope it does not cause other confusions!

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