从 matplotlib 和噪声中获取 'module has no attribute'

getting 'module has no attribute' from matplotlib and noise

我正在使用 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'

我不知道这是解释器问题还是什么

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