项目场景:终极目的是将docx文件中的图片提取出来,首先要下载docx库
我使用的是python3.8,安装docx库很顺利,直接
pip install docx
就安装好了,但是运行代码提示
Import Error: No module named ‘exceptions‘
docx库还没有完全兼容python3
1、先卸载docx,输入命令:
pip uninstall docx
2、再重新安装,输入命令:
pip install python-docx
PS: 在这里我又遇到了一个问题,命令安装python-docx的时候报错提示pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org',
这是由于使用pip安装模块的时候,网络波动,解决方法如下:
设置国内镜像源,设置超时(替换模块名称即可)
pip --default-timeout=100 install python-docx -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
--trusted-host pypi.douban.com:表示信任豆瓣镜像地址
切换为其他国内镜像地址(替换命令中的网址即可):
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学:http://pypi.hustunique.com/
参考博客如下:
————————————————
原文链接:https://blog.csdn.net/weixin_45162779/article/details/125788489
原文链接:https://blog.csdn.net/yuan2019035055/article/details/126441902