在 python3.3 中导入 docx 时出现错误 ImportError: No module named 'exceptions'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22765313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When import docx in python3.3 I have error ImportError: No module named 'exceptions'
提问by user3472559
when I import docx
I have this error:
当我导入时docx
出现此错误:
>File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docx-0.2.4-py3.3.egg/docx.py", line 30, in <module>
from exceptions import PendingDeprecationWarning
ImportError: No module named 'exceptions'
How to fix this error (python3.3
, docx 0.2.4
)?
如何修复此错误 ( python3.3
, docx 0.2.4
)?
回答by Dmitry
The problem, as was noted previously in comments, is the docx module was not compatible with Python 3. It was fixed in this pull-request on github: https://github.com/mikemaccana/python-docx/pull/67
正如之前在评论中指出的,问题是 docx 模块与 Python 3 不兼容。它已在 github 上的此拉取请求中修复:https: //github.com/mikemaccana/python-docx/pull/67
Since the exception is now built-in, the solution is to not import it.
由于异常现在是内置的,因此解决方案是不导入它。
docx.py
@@ -27,7 +27,12 @@
except ImportError:
TAGS = {}
-from exceptions import PendingDeprecationWarning
+# Handle PendingDeprecationWarning causing an ImportError if using Python 3
+try:
+ from exceptions import PendingDeprecationWarning
+except ImportError:
+ pass
+
from warnings import warn
import logging
回答by Vancent
- Uninstall docx module with
pip uninstall docx
- Download
python_docx-0.8.6-py2.py3-none-any.whl
file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ - Run
pip install python_docx-0.8.6-py2.py3-none-any.whl
to reinstall docx. This solved the above import error smoothly for me. Just to provide a solution...
- 卸载 docx 模块
pip uninstall docx
python_docx-0.8.6-py2.py3-none-any.whl
从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载文件- 运行
pip install python_docx-0.8.6-py2.py3-none-any.whl
以重新安装 docx。这为我顺利解决了上述导入错误。只是为了提供解决方案......
回答by ijijij
You may be install docx
, not python-docx
您可能正在安装docx
,而不是python-docx
You can see this for install python-docx
你可以看到这个进行安装 python-docx
http://python-docx.readthedocs.io/en/latest/user/install.html#install
http://python-docx.readthedocs.io/en/latest/user/install.html#install
回答by Arun
If you are using python 3x don't do pip install docx
instead go for
如果您正在使用python 3X不这样做pip install docx
,而不是去
pip install python-docx
It is compatible with python 3.x
它与python 3.x兼容
Official Documentation available here: https://pypi.org/project/python-docx/
官方文档可在此处获得:https: //pypi.org/project/python-docx/
回答by sajid
In Python 3 exceptions module was removed and all standard exceptions were moved to builtin module. Thus meaning that there is no more need to do explicit import of any standard exceptions.
在 Python 3 中,异常模块被删除,所有标准异常都被移动到内置模块中。这意味着不再需要显式导入任何标准异常。
回答by Brighton Chinhongo
I had the same problem, but pip install python-docx
worked for me, I'm using python 3.7.1
我遇到了同样的问题,但pip install python-docx
对我有用,我使用的是 python 3.7.1
回答by Shagun
You need to make it work with python3.
你需要让它与python3一起工作。
sudo pip3 install python-docx
This installation worked for me in Python3 without any further additions.
这个安装在 Python3 中对我有用,没有任何进一步的添加。
python3
>> import docx
PS: Note that the 'pip install python-docx' or apt-get python3-docx are not useful.
PS:请注意,'pip install python-docx' 或 apt-get python3-docx 没有用。
回答by Kalpit
If you're using python 3.x, Make sure you have both python-docx& docxinstalled.
如果您使用的是 python 3.x,请确保同时安装了python-docx和docx。
Installing python-docx :
安装 python-docx :
pip install python-docx
Installing docx :
安装 docx :
pip install docx