How to resolve ImportError: cannot import name 'makeMappingArray' from 'matplotlib.colors'
How to resolve ImportError: cannot import name 'makeMappingArray' from 'matplotlib.colors'
我正在学习使用 python 3.9.0 中的 wordcloud 和 stylecloud 库进行编码。我为 stylecloud 库编写了基本代码,但它给出了一个错误:
ImportError: cannot import name 'makeMappingArray' from 'matplotlib.colors'
这是代码:
import wordcloud
import matplotlib
def cloud_design():
stylecloud.gen_stylecloud(file_path=r"C:\Users\Edwin Anil\OneDrive - AL RAYAN HOLDING CO\ALL PYTHON CODES\word cloud text file.txt",icon_name="<i class='fas fa-guitar'></i>")
cloud_design()
正在使用的 wordcloud 版本是 wordcloud-1.8.1
。
正在使用的 matplotlib 版本是 matplotlib-3.4.1
.
这是完整的错误信息:
File "C:\Users\Edwin Anil\OneDrive - AL RAYAN HOLDING CO\ALL PYTHON CODES\word cloud.py", line 1, in <module>
import stylecloud
File "C:\Users\Edwin Anil\AppData\Local\Programs\Python\Python39\lib\site-packages\stylecloud\__init__.py", line 1, in <module>
from .stylecloud import gen_stylecloud
File "C:\Users\Edwin Anil\AppData\Local\Programs\Python\Python39\lib\site-packages\stylecloud\stylecloud.py", line 6, in <module>
from matplotlib.colors import makeMappingArray, to_rgb
ImportError: cannot import name 'makeMappingArray' from 'matplotlib.colors' (C:\Users\Edwin Anil\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\colors.py)```
I did try various other syntax forms for import and tried uninstalling and reinstalling matplotlib too but I don't seem to figure it out. Some help is appreciated.
复制html时,只需输入class名称即可。例如“fas fa-guitar”:
import wordcloud
import matplotlib
import stylecloud
def cloud_design():
stylecloud.gen_stylecloud(file_path="my_random.txt",icon_name="fas fa-guitar")
cloud_design()
输出:
guitar
好的,按照@simpleApp的解决方案。我尝试降级到旧版本的 matplotlib 并且它有效。
cmd 命令是 pip install matplotlib==3.2.2
结果如下:
我正在学习使用 python 3.9.0 中的 wordcloud 和 stylecloud 库进行编码。我为 stylecloud 库编写了基本代码,但它给出了一个错误:
ImportError: cannot import name 'makeMappingArray' from 'matplotlib.colors'
这是代码:
import wordcloud
import matplotlib
def cloud_design():
stylecloud.gen_stylecloud(file_path=r"C:\Users\Edwin Anil\OneDrive - AL RAYAN HOLDING CO\ALL PYTHON CODES\word cloud text file.txt",icon_name="<i class='fas fa-guitar'></i>")
cloud_design()
正在使用的 wordcloud 版本是 wordcloud-1.8.1
。
正在使用的 matplotlib 版本是 matplotlib-3.4.1
.
这是完整的错误信息:
File "C:\Users\Edwin Anil\OneDrive - AL RAYAN HOLDING CO\ALL PYTHON CODES\word cloud.py", line 1, in <module>
import stylecloud
File "C:\Users\Edwin Anil\AppData\Local\Programs\Python\Python39\lib\site-packages\stylecloud\__init__.py", line 1, in <module>
from .stylecloud import gen_stylecloud
File "C:\Users\Edwin Anil\AppData\Local\Programs\Python\Python39\lib\site-packages\stylecloud\stylecloud.py", line 6, in <module>
from matplotlib.colors import makeMappingArray, to_rgb
ImportError: cannot import name 'makeMappingArray' from 'matplotlib.colors' (C:\Users\Edwin Anil\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\colors.py)```
I did try various other syntax forms for import and tried uninstalling and reinstalling matplotlib too but I don't seem to figure it out. Some help is appreciated.
复制html时,只需输入class名称即可。例如“fas fa-guitar”:
import wordcloud
import matplotlib
import stylecloud
def cloud_design():
stylecloud.gen_stylecloud(file_path="my_random.txt",icon_name="fas fa-guitar")
cloud_design()
输出: guitar
好的,按照@simpleApp的解决方案。我尝试降级到旧版本的 matplotlib 并且它有效。
cmd 命令是 pip install matplotlib==3.2.2
结果如下: