首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从matplotlib和noise中获取“module has no attribute”

从matplotlib和noise中获取“module has no attribute”
EN

Stack Overflow用户
提问于 2020-05-14 03:56:14
回答 1查看 123关注 0票数 1

我使用的是Python 3.7.4,Windows 10和matplotlib 3.2.1,图像1.5.31,噪声1.2.2,枕头7.1.2,我正在尝试让这段代码工作

代码语言:javascript
复制
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')

当我运行它时,我会得到

代码语言:javascript
复制
AttributeError: module 'matplotlib' has no attribute 'pyplot'

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

代码语言:javascript
复制
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

我得到了

代码语言:javascript
复制
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)

我也得到了

代码语言:javascript
复制
AttributeError: module 'noise' has no attribute 'pnoise2'

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-17 01:02:23

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61783694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档