Closed plooney closed 7 years ago
Thanks for the information. Since I can't reproduce the error using Python 2, it seems to be an issue with Python 3 and singleton classes (using the factory method).
Can you reproduce the error using Python 2?
I get a little further in Python2 but I get this error when loading
medpy.core.exceptions.ImageLoadingError: Failes to load image 1/1_Prim.mha as Itk/Vtk MetaImage (.mhd, .mha/.raw). Reason signaled by third-party module: 'LazyITKModule' object has no attribute 'AnalyzeImageIO
This problem stems from way ITK has been wrapped, not from MedPy.
When wrapping ITK for Python using WrapITK, each class desired has to be included explicitly. WrapITK does not provide a complete interface to ITK by itself.
Your version does not seem to include the itkAnalyzeImageIO class required by MedPy to load images. This probably means that the optional ITK module "IO" has not been included during compilation. You will have to compile it again.
Could you tell me, how you've acquired the ITK Python wrappings? And what configuration (with cmake) you've used? Best post a copy of your ccmake config.
For now, try to stick to image formats supported by NiBabel (see http://pythonhosted.org//MedPy/information/imageformats.html).
Hello, I have exactly the same problem with medpy : medpy.core.exceptions.ImageLoadingError: Failes to load image .../image.mha as Itk/Vtk MetaImage (.mhd, .mha/.raw). Reason signaled by third-party module: 'LazyITKModule' object has no attribute 'AnalyzeImageIO'
The problem is that the said module "AnalyzeImageIO" is deprecated under ITKv4 (which has already been running for quite a long time) so I don't really udnerstand how is it that medpy still needs it (http://www.itk.org/Doxygen42/html/classitk_1_1AnalyzeImageIO.html) ? Does it mean that I need to install ITKv3 to get medpy working with python?
Am I missing something here ?
Here is my CMake configuration for ITK v 4.7.2:
Dear MMRohe,
thank you for reporting this and attaching your CMake config. As far as I can see, everything seems to be in order. MedPy has actually been testen with ITK 4.7 (http://pythonhosted.org/MedPy/installation/itkwrapper4.7.html), so I can't find the error immediately. You even have ITKV3_COMPATIBILITY=ON set, hence the AnalyzeImageIO should be available.
Today I am not a machine with ITK. I will look into the issue tomorrow and come back to you.
To tell the truth, keeping up with the changes in ITK and the very buggy behaviour of its Python Wrapper is very tedious and I often miss recent changes. I tend to use Convert3D (http://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md) to convert all images to NIfTI format and work with them, which improves stability and avoids loading the very large itk python module.
Best, loli
Hello loli,
thanks for your answer. I also use Nifti format and using it to make it work with Python could be a solution but with the data I am working on at the moment it would not be very convenient.
Indeed, the problem is quite weird. One thing I could think of, is that either the medpy version is outdated or the version of ITK that medPy is linked to is not the correct one (because I have several ITK versions on my computer) but I have double checked the link and the other ITK do not have the python wrapper built in anyway. Do you know if there is command inside python that could show exactly which version of the module it is using (I tried print medpy.version or print itk.version but these attributes dont exist).
Anyway, thanks a lot for your help, if you manage to get a solution or have any idea don't hesitate to contact me :)
Best,
Marc-Michel
On 01/11/2016 02:21 PM, loli wrote:
Dear MMRohe,
thank you for reporting this and attaching your CMake config. As far as I can see, everything seems to be in order. MedPy has actually been testen with ITK 4.7 (http://pythonhosted.org/MedPy/installation/itkwrapper4.7.html), so I can't find the error immediately. You even have ITKV3_COMPATIBILITY=ON set, hence the AnalyzeImageIO should be available.
Today I am not a machine with ITK. I will look into the issue tomorrow and come back to you.
To tell the truth, keeping up with the changes in ITK and the very buggy behaviour of its Python Wrapper is very tedious and I often miss recent changes. I tend to use Convert3D (http://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md) to convert all images to NIfTI format and work with them, which improves stability and avoids loading the very large itk python module.
Best, loli
— Reply to this email directly or view it on GitHub https://github.com/loli/medpy/issues/6#issuecomment-170546516.
The ITK wrappers are fragile things. Trying
import inspect
import itk
inspect.getfile(itk)
tells me that it is an build-in module, which we know to be false. Well, nothing to be done about it. I could simply look at my PYTHONPATH to figure out, which one I am using.
Currently, I am still compiling ITK 4.7, I will come back to you later. It might take till next week, I fear :/
Best, loli
Fixed with the newest commit to https://github.com/loli/medpy/
Enjoy! loli
thx for your answer ! (and sorry I did not reply back earlier, had some problem with my comp so could not try it)
so it seems the update has fixed the previous issue but not I get the following message. It seems weird that it calls the load_nibabel function for a .mha image ?
ImageLoadingError Traceback (most recent call last)
Mhh... my version is loading MHA images just fine. Could you attached a zipped version of your image for me for testing?
The __load_nibabel error results from the way MedPy loads images: First, it tries to find the best module depending on the image type. If that loader fails, it tries all available ones on a brute-force basis and returns the error of the last one tested.
I don't know if this issue is still being tracked, but I am also having similar problems. When I try to load .mha files, I get a bunch of warnings, followed by the error: _raise err medpy.core.exceptions.ImageLoadingError: Failes to load image Registered-1808820224_Classification.mha as Itk/Vtk MetaImage (.mhd, .mha/.raw). Reason signaled by third-party module: 'LazyITKModule' object has no attribute 'AnalyzeImageIO' _
I set the ITK V3_COMPATIBILITY flag = ON during make. I am using ITK 4.9 and I am using Python 2.7
Did you install the PYPI 2.2 or the GitHub develoment version?
Hi loli, I am getting same error as of raghuramdr. How can i correct it .
Best
Same problem as @plooney.
Conda virtual environment with python 3.6.1, numpy 1.12.1 and scipy 0.19.0.
I install medpy with
$ pip install medpy
Collecting medpy
Requirement already satisfied: numpy>=1.6.1 in /home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages (from medpy)
Requirement already satisfied: scipy>=0.9.0 in /home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages (from medpy)
Installing collected packages: medpy
Successfully installed medpy-0.2.2
Then, importing load() fails
$ python -c 'from medpy.io import load'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages/medpy/io/__init__.py", line 59, in <module>
from .load import load
File "/home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages/medpy/io/load.py", line 28, in <module>
from . import header
File "/home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages/medpy/io/header.py", line 27, in <module>
from ..core import Logger
File "/home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages/medpy/core/__init__.py", line 55, in <module>
from .logger import Logger
File "/home/rcasero/.conda/envs/cytometer/lib/python3.6/site-packages/medpy/core/logger.py", line 94
raise RuntimeError, 'Only one instance of Logger is allowed!'
^
SyntaxError: invalid syntax
Same error as @rcasero
@loli , details on how to reproduce the error
Install conda
Miniconda2-latest-Linux-x86_64.sh
).Make the script executable and run it as root
cd ~/Downloads
chmod u+x Miniconda2-latest-Linux-x86_64.sh
sudo ./Miniconda2-latest-Linux-x86_64.sh
/opt/miniconda2
, rather than the default /home/rcasero/miniconda2
.Create a conda environment for the test (python 3.6 at the time of this writing)
conda create --name test python=3
Activate the conda environment
source activate test
Install medpy
pip install medpy
test medpy
python -c 'from medpy.io import load'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/rcasero/.conda/envs/test/lib/python3.6/site-packages/medpy/io/__init__.py", line 59, in <module>
from .load import load
File "/home/rcasero/.conda/envs/test/lib/python3.6/site-packages/medpy/io/load.py", line 28, in <module>
from . import header
File "/home/rcasero/.conda/envs/test/lib/python3.6/site-packages/medpy/io/header.py", line 27, in <module>
from ..core import Logger
File "/home/rcasero/.conda/envs/test/lib/python3.6/site-packages/medpy/core/__init__.py", line 55, in <module>
from .logger import Logger
File "/home/rcasero/.conda/envs/test/lib/python3.6/site-packages/medpy/core/logger.py", line 94
raise RuntimeError, 'Only one instance of Logger is allowed!'
^
SyntaxError: invalid syntax
This thread addresses two separate problems which are both solved.
Problem 1 raise RuntimeError, 'Only one instance of Logger is allowed!'
If you are encountering this problem, you are using Python 3. Officially, MedPy only supports Python 2. But, thanks for an effort from @mamrehn, the current master branch might just be Python 3 compatible. I.e., get the newest MedPy version from https://github.com/loli/medpy. (@rcasero and @kvrd18)
Problem 2 Reason signaled by third-party module: 'LazyITKModule' object has no attribute 'AnalyzeImageIO'
See Issue #15. Solved in the master current master branch. I.e., get the newest MedPy version from https://github.com/loli/medpy. (@raghuramdr and @sajjo79)
I have installed using pip3