我使用的是Python 3.7.4,Windows 10和matplotlib 3.2.1,图像1.5.31,噪声1.2.2,枕头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'我不知道这是一个解释器的问题还是什么
发布于 2020-05-17 01:02:23
顺便说一句,这似乎是conda包与非conda包冲突的问题。当我卸载conda时,它现在似乎起作用了。
https://stackoverflow.com/questions/61783694
复制相似问题