简体   繁体   English

模块“蚂蚁”没有属性“from_numpy”

[英]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 模块正确安装在您的虚拟环境中的步骤:

  1. python3 -m venv env_name : this will create a virtual env in your current path python3 -m venv env_name :这将在您当前的路径中创建一个虚拟环境
  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 source env/bin/activate :这将激活您的虚拟环境(如果在 Windows 上,只需 cd 进入您的环境名称中的激活.\env\Scripts\activate
  3. If your using vscode hit ctrl+shift+p then select interpreter then go to your created env如果您使用 vscode 点击 ctrl+shift+p 然后选择解释器然后转到您创建的环境
  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现在我们有了我们的虚拟环境,只需点击pip install antspyx然后检查pip list并在您的终端中查看该软件包是否已正确安装
  5. If you still have the error restart your IDE如果仍然出现错误,请重新启动 IDE

你有没有尝试过:

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.

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