Crispy13
Crispy13

Reputation: 369

About import modules in python

import nibabel

nibabel.processing.resample_to_output(input_img, voxel_size)

AttributeError: module 'nibabel' has no attribute 'processing'
import nibabel
import nibabel.processing

nibabel.processing.resample_to_output(input_img, voxel_size)

Why does the first code fail but the second code work?

Upvotes: 0

Views: 521

Answers (1)

AzyCrw4282
AzyCrw4282

Reputation: 7744

Expanding on @juanpa answer in the comments, you can simply consider these as two different modules.

For this

import nibabel

You get the error which suggests that this module does not have an attribute named processing

But for this

import nibabel.processing

It works fine since itself can be considered a module and thus means that processing is not an attribute of nibabel.

So it looks the code that you are trying to run only requires the 2nd import and not the first.

Upvotes: 1

Related Questions