python3.8版本安装basemap的方法 & FIX THE ERROR : cannot import name ‘dedent’ from ‘matplotlib.cbook’

*python3.8版本安装basemap的方法*

请先根据该参考资料进行安装: http://blog.sciencenet.cn/blog-3429473-1224163.html

注意 如果用anaconda使用的python编译环境,那么在第四步:
将下载好的.whl文件放在python安装目录的Scripts文件夹下:

  1. 我们应寻找的目录应该是anaconda3/envs/XXX(自己环境的文件夹)/Scripts 文件夹下
  2. 然后在anaconda3 prompt中自己的envs中安装basemap:
    (XXX)C:/用户/DELL/anaconda3/envs/XXX(自己环境的文件夹)/Scripts>> pip install basemap-1.2.1-cp38-cp38-win_amd64.whl
  3. 安装成功,会有以下提示:Successfully installed basemap-1.2.2
    安装成功提示
  4. 最后需要conda list中确认以下basemap库是否安装成功
    在这里插入图片描述
  5. 安装完basemap后,可以尝试执行 from mpl_toolkits.basemap import Basemap
    发现会报错FIX THE ERROR : cannot import name ‘dedent’ from ‘matplotlib.cbook’

解决方法:
参考资料 https://www.youtube.com/watch?v=MCl6qY7VqRM

是因为anaconda3/envs/XXX(自己环境名称)/lib/site-packages/matplotib/cbook/init.py文件缺少dedent的定义,用notepad打开_init_.py,搜索"dedent"
在这里插入图片描述
将以下复制到_dedent_regex={}的下一行,并保存文件退出,发现错误解决。

def dedent(s):
    """
    Remove excess indentation from docstring *s*.
    Discards any leading blank lines, then removes up to n whitespace
    characters from each line, where n is the number of leading
    whitespace characters in the first line. It differs from
    textwrap.dedent in its deletion of leading blank lines and its use
    of the first non-blank line to determine the indentation.

    It is also faster in most cases.
    """
    # This implementation has a somewhat obtuse use of regular
    # expressions.  However, this function accounted for almost 30% of
    # matplotlib startup time, so it is worthy of optimization at all
    # costs.

    if not s:      # includes case of s is None
        return ''

    match = _find_dedent_regex.match(s)
    if match is None:
        return s

    # This is the number of spaces to remove from the left-hand side.
    nshift = match.end(1) - match.start(1)
    if nshift == 0:
        return s

    # Get a regex that will remove *up to* nshift spaces from the
    # beginning of each line.  If it isn't in the cache, generate it.
    unindent = _dedent_regex.get(nshift, None)
    if unindent is None:
        unindent = re.compile("\n\r? {0,%d}" % nshift)
        _dedent_regex[nshift] = unindent

    result = unindent.sub("\n", s).strip()
    return result
  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 13
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值