Search code examples
pythonmatplotlibpython-importnoise

getting 'module has no attribute' from matplotlib and noise


I'm using Python 3.7.4, Windows 10 with matplotlib 3.2.1, image 1.5.31, noise 1.2.2, pillow 7.1.2 and am trying to get this code to work

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')

When I run it I get

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

and if I change the import of matplotlib (with or without the Agg line) to

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

I get

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)

Ive also been getting

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

I can't tell if this is an interpreter issue or what


Solution

  • btw it seems it was a problem with conda packages conflicting with non-conda packages. Seems to work now when I uninstalled conda.