pybinding 无法导入名称 allow_rasterization

pybinding cannot import name allow_rasterization

我刚刚安装了 pybinding,我正在尝试 运行 该库文档中提出的第一个示例。

import pybinding as pb
import numpy as np
import matplotlib.pyplot as plt
import pybinding as pb

d = 0.2  # [nm] unit cell length
t = 1    # [eV] hopping energy

# create a simple 2D lattice with vectors a1 and a2
lattice = pb.Lattice(a1=[d, 0], a2=[0, d])
lattice.add_sublattices(
    ('A', [0, 0])  # add an atom called 'A' at position [0, 0]
)
lattice.add_hoppings(
    # (relative_index, from_sublattice, to_sublattice, energy)
    ([0, 1], 'A', 'A', t),
    ([1, 0], 'A', 'A', t)
)

lattice.plot()
plt.show() 

我已经很好地安装了文档(Windows OS)和 sicrpt 运行 所需的内容,直到它必须执行 lattice.plot( ) 抛出以下错误

Traceback (most recent call last):
  File "prueba.py", line 25, in <module>
    lattice.plot()
  File "C:\xampp7\Python\lib\site-packages\pybinding\lattice.py", line 463, in plot
    axes=axes))
  File "C:\xampp7\Python\lib\site-packages\pybinding\results.py", line 598, in plot
    plot_sites(self.positions, self.sublattices, **props['site'])
  File "C:\xampp7\Python\lib\site-packages\pybinding\system.py", line 285, in plot_sites
    from pybinding.support.collections import CircleCollection
  File "C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py", line 2, in <module>
    from matplotlib.collections import Collection, allow_rasterization
ImportError: cannot import name 'allow_rasterization' 

我已经检查并正确安装了 matplotlib(我尝试了 matplotlib 文档中推荐的一些绘图并且效果很好)。还在 pybinding 库中查找文件 collections.py,错误在第二行

import numpy as np
from matplotlib.collections import Collection, allow_rasterization

然后查看 matplolib 的 collections.py 并搜索 'allow_rasterization' 我发现以下函数重复 6 次

@artist.allow_rasterization
def draw(self, renderer):

我是 python 的新手,所以我不知道我是否在看我应该看的东西。提前致谢

我卸载了 matplotlib 的 2.2.2 版并安装了 marplotlib 的 1.1.2 版。 我现在可以 put.show()

进入文件"C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py"并将命令行修改为: "来自 matplotlib.collections 导入集合#,allow_rasterization 从 matplotlib.artist 导入 allow_rasterization"

我遇到了同样的问题。我正在使用 Linux 并且软件包 pybinding 安装在

/usr/lib/python3.6/site-packages/pybinding/support/

您可以更正错误更改 allow_rasterization 模块的导入模块,更改文件 colletion.py

/usr/lib/python3.6/site-packages/pybinding/support/colletion.py

第一行来自

import numpy as np
from matplotlib.collections import Collection, allow_rasterization

import numpy as np
from matplotlib.collections import Collection
from matplotlib.artist import allow_rasterization

您可以在 matplotlib 1.1.2 上更正与以前版本相关的绘图问题,因为现在 pybinding 包使用 matplotlib 2.2.2.

进入目录: ~/miniconda3/lib/python3.7/site-packages/pybinding/support

在文件中:collections.py 更改第 2 行:

from matplotlib.collections import Collection, allow_rasterization

from matplotlib.collections import Collection 
from matplotlib.artist import allow_rasterization