从matplotlib和noise获取“模块没有属性”

2024-05-19 14:31:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python 3.7.4、Windows 10和matplotlib 3.2.1、image 1.5.31、noise 1.2.2、pillow 7.1.2,并试图让这些代码正常工作

import noise
import numpy as np
import matplotlib
from mpl_toolkits.mplot3d import axes3d

shape = (50,50)
scale = 100.0
octaves = 6
persistence = 0.5
lacunarity = 2.0

world = np.zeros(shape)
for i in range(shape[0]):
    for j in range(shape[1]):
        world[i][j] = noise.pnoise2(i/scale,
                                    j/scale,
                                    octaves=octaves,
                                    persistence=persistence,
                                    lacunarity=lacunarity,
                                    repeatx=1024,
                                    repeaty=1024,
                                    base=42)

plt.imshow(world,cmap='terrain')

当我运行它时,我得到

AttributeError: module 'matplotlib' has no attribute 'pyplot'

如果我将matplotlib的导入(带或不带Agg行)更改为

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

我明白了

File "C:\Users\chris\AppData\Roaming\Python\Python37\site-packages\PIL\Image.py", line 93, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (C:\Users\chris\AppData\Roaming\Python\Python37\site-packages\PIL\__init__.py)

我也越来越

AttributeError: module 'noise' has no attribute 'pnoise2'

我不知道这是不是口译员的问题


Tags: infromimportworldpilmatplotlibasnp
1条回答
网友
1楼 · 发布于 2024-05-19 14:31:50

顺便说一句,康达包与非康达包冲突似乎是个问题。当我卸载conda时,它现在似乎可以工作了

相关问题 更多 >