主要写了解决问题的思路,解决办法在最底部。
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'
,然后再导入,成功了。
希望可以帮到您,如果对您有用点个赞好不好,感谢。