简体   繁体   English

如何修复 AttributeError:模块“magpylib”没有属性“源”

[英]How to Fix AttributeError: module 'magpylib" has no attribute 'source'

I have tried installing the magpylib module onto both VSCode and Anaconda(Spyder) and have received identical errors.我尝试将 magpylib 模块安装到 VSCode 和 Anaconda(Spyder) 上,并收到相同的错误。 I am relatively new to programming and do not know how to fix it, neither have I found a similar question.我对编程比较陌生,不知道如何解决它,我也没有找到类似的问题。 For the code I used the first example code given by the site .对于代码,我使用了网站给出的第一个示例代码。

# imports
import numpy as np
import matplotlib.pyplot as plt
import magpylib as magpy

# create magnets
magnet1 = magpy.source.magnet.Box(mag=[0,0,600],dim=[3,3,3],pos=[-4,0,3])
magnet2 = magpy.source.magnet.Cylinder(mag=[0,0,500], dim=[3,5], pos=[0,0,0])

# manipulate magnets
magnet1.rotate(45,[0,1,0],anchor=[0,0,0])
magnet2.move([5,0,-4])

# collect magnets
pmc = magpy.Collection(magnet1,magnet2)

# display system geometry
pmc.displaySystem()

# calculate B-fields on a grid
xs = np.linspace(-10,10,20)
zs = np.linspace(-10,10,20)
Bs = np.array([[pmc.getB([x,0,z]) for x in xs] for z in zs])

# display fields using matplotlib
fig, ax = plt.subplots()
X,Y = np.meshgrid(xs,zs)
U,V = Bs[:,:,0], Bs[:,:,2]
ax.streamplot(X, Y, U, V, color=np.log(U**2+V**2), density=1.5)
plt.show() 

Here is the solution:这是解决方案:

import magpylib as magpy

magnet1 = magpy.magnet.Box(magnetization=[0, 0, 600], dimension=[3, 3, 3], position=[-4, 0, 3])

You might have found a deprecated example.您可能已经找到了一个已弃用的示例。

For your future questions, please provide a minimal code, ie a code reproducing the error in a minimum of lines AND you python version.对于您未来的问题,请提供最少的代码,即以最少的行数重现错误的代码和您的 python 版本。 In your case :在你的情况下:

import magpylib as magpy

magnet1 = magpy.source.magnet.Box(mag=[0, 0, 600], dim=[3, 3, 3], pos=[-4, 0, 3])

尝试安装旧版本的 magpylib 例如:

pip install magpylib==2.3.0b0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复“AttributeError:模块'keras.backend'没有属性..” - How to fix "AttributeError: module 'keras.backend' has no attribute.." 如何修复此错误“AttributeError:模块‘socket’没有属性‘gethostname’” - How to fix this error "AttributeError: module 'socket' has no attribute 'gethostname'" 如何修复 AttributeError: 'module' 对象没有属性 'function'? - How to fix AttributeError: 'module' object has no attribute 'function'? 如何修复“AttributeError:‘module’对象没有属性‘x’”? - how to fix "AttributeError: 'module' object has no attribute 'x' "? 如何修复AttributeError:模块'testing2'没有属性'printPackage'? - How to fix AttributeError: module 'testing2' has no attribute 'printPackage'? 如何在wfastcgi中修复“ AttributeError:模块没有属性'wsgi'” - How to fix “AttributeError: module has no attribute 'wsgi' ” in wfastcgi 如何修复:AttributeError:模块“整洁”没有属性“配置” - How to fix: AttributeError: module 'neat' has no attribute 'config' 如何修复 AttributeError:模块“tensorflow”没有属性“ConfigProto” - How can I fix AttributeError: module 'tensorflow' has no attribute 'ConfigProto' 如何修复 AttributeError:模块“requests.sessions”没有属性“post” - How to Fix AttributeError: module 'requests.sessions' has no attribute 'post' AttributeError:模块没有属性 - AttributeError: module has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM