[英]module 'ants' has no attribute 'from_numpy'
I am working in a jupyter notebook, and used pip to install ANTsPy:我正在使用 jupyter 笔记本,并使用 pip 安装 ANTsPy:
pip install antspyx
However, using the function from_numpy
throws an error:但是,使用函数
from_numpy
会引发错误:
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.我也尝试过使用
import ants.from_numpy
导入蚂蚁,但这不起作用。
Can you please specify your IDE+ if you took care of activating the virtualenv?如果您负责激活 virtualenv,请指定您的 IDE+ 吗?
Anyways here are the steps to make sure that the python module is propoerly installed in your virtual environment :无论如何,这里是确保 python 模块正确安装在您的虚拟环境中的步骤:
python3 -m venv env_name
: this will create a virtual env in your current path python3 -m venv env_name
:这将在您当前的路径中创建一个虚拟环境source env/bin/activate
: this will activate your virtual env (if on windows just cd into activate within your env name .\env\Scripts\activate
source env/bin/activate
:这将激活您的虚拟环境(如果在 Windows 上,只需 cd 进入您的环境名称中的激活.\env\Scripts\activate
pip install antspyx
then check with pip list
and see in your terminal if the package is propoerly installedpip install antspyx
然后检查pip list
并在您的终端中查看该软件包是否已正确安装你有没有尝试过:
from ants import from_numpy
The issue in this case was scipy versioning.这种情况下的问题是 scipy 版本控制。 I downgraded from version 1.7.3 to version 1.2.0, which then solved the problem.
我从版本 1.7.3 降级到版本 1.2.0,然后解决了问题。 Why?
为什么? It's because ants library expects a function called "factorial" in scipy.misc, but version 1.7.3 moved the location of factorial.
这是因为 ants 库在 scipy.misc 中需要一个名为“factorial”的函数,但 1.7.3 版本移动了 factorial 的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.