pip导包时产生错误,UnicodeDecodeError: 'gbk' codec can't decode byte.....illegal multibyte sequence(已解决)

主要写了解决问题的思路,解决办法在最底部。

pip导入python包时产生错误:
在这里插入图片描述

    ERROR: Command errored out with exit status 1:
     command: 'd:\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\AppData\\Local\\Temp\\pip-install-t2537m2t\\django-mdeditor\\setup.py'"'"'; __file__='"'"'C:\\Users\\AppData\\Local\\Temp\\pip-install-t2537m2t\\django-mdeditor\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\AppData\Local\Temp\pip-install-t2537m2t\django-mdeditor\pip-egg-info'
         cwd: C:\Users\AppData\Local\Temp\pip-install-t2537m2t\django-mdeditor\
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\AppData\Local\Temp\pip-install-t2537m2t\django-mdeditor\setup.py", line 6, in <module>
        long_description = readme.read()
    UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 167: illegal multibyte sequence
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

其中有一个文件路径"C:\Users\AppData\Local\Temp\pip-install-t2537m2t\django-mdeditor\setup.py",然后寻找相关隐藏文件,发现该文件夹不存在。

后来猜测可能是导入的的包无法读取,于是下载依据导包时出现的链接下载了相关的压缩文件。解压缩之后发现了一个setup.py文件,联想到文件路径中的django-mdeditor\setup.py,打开后找到了第六行的

long_description = readme.read()

于是我判断是这个位置出现了问题。
于是做了以下尝试

long_description = readme.read(encoding='utf-8')
long_description = readme.read().decode()
long_description = readme.read(errors='ignore')

几次导包都出现了错误,然后我又重新看了以下代码,发现了五六两行如下。

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
    long_description = readme.read()

大家有可能猜到了我做了什么操作

with open(os.path.join(os.path.dirname(__file__), 'README.md'),encoding='utf-8') as readme:
    long_description = readme.read()

错误不在read部分,而在上面open部分,在with open内部加入了encoding='utf-8',然后再导入,成功了。

在这里插入图片描述
希望可以帮到您,如果对您有用点个赞好不好,感谢。

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值