简体   繁体   中英

module 'ants' has no attribute 'from_numpy'

I am working in a jupyter notebook, and used pip to install ANTsPy:

pip install antspyx

However, using the function from_numpy throws an error:

import ants

Im2Use=Im[0,:,:,:]
fixed, moving, mytx=reg(Im2Use, t_rz)
fwdtransforms=mytx['fwdtransforms']
fixed_ants= ants.from_numpy(Im2Use.astype(float))
moving_ants= ants.from_numpy(t_rz.astype(float))
mywarpedimage=ants.apply_transforms( fixed=fixed_ants, moving=moving_ants,transformlist=fwdtransforms)

AttributeError: module 'ants' has no attribute 'from_numpy'

How can I solve this? I've also tried importing ants using import ants.from_numpy , but that did not work.

Can you please specify your IDE+ if you took care of activating the virtualenv?

Anyways here are the steps to make sure that the python module is propoerly installed in your virtual environment :

  1. python3 -m venv env_name : this will create a virtual env in your current path
  2. source env/bin/activate : this will activate your virtual env (if on windows just cd into activate within your env name .\env\Scripts\activate
  3. If your using vscode hit ctrl+shift+p then select interpreter then go to your created env
  4. now we have our virtual environment just hit pip install antspyx then check with pip list and see in your terminal if the package is propoerly installed
  5. If you still have the error restart your IDE

你有没有尝试过:

from ants import from_numpy

The issue in this case was scipy versioning. I downgraded from version 1.7.3 to version 1.2.0, which then solved the problem. Why? It's because ants library expects a function called "factorial" in scipy.misc, but version 1.7.3 moved the location of factorial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM