简体   繁体   中英

Why am I getting this ImportError when trying to import docx in the Terminal?

I'm learning Python at the moment, and after installing the docx module, I keep getting this error when trying to import it in the Terminal:

import docx Traceback (most recent call last): File "", line 1, in File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/ init .py", line 14, in from docx.parts.document import DocumentPart File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/parts/document.py", line 7, in from docx.document import Document File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/document.py", line 10, in from docx.section import Section, Sections File "/Users/trevorstathatos/Library/Python/3.10/lib/python/site-packages/docx/section.py", line 7, in from collections import Sequence ImportError: cannot import name 'Sequence' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/ init .py)

When trying to import it to my Mu Editor, I get this error:

import docx

~/Library/Application Support/mu/mu_venv-38-20211212-105811/lib/python3.8/site-packages/docx.py in 28 TAGS = {} 29 ---> 30 from exceptions import PendingDeprecationWarning 31 from warnings import warn 32

ModuleNotFoundError: No module named 'exceptions'

Can someone please help me figure out how to fix this problem? Thanks.

I have readed on internet and a solution may be:

$ pip install python-docx
#instead of pip install docx

(for python 3.x) Please try this and tell me if works Link: https://flutterq.com/solved-import-no-module-named-exceptions/

You can use where python command in cmd to find the path that python is installed in. then you can use this command -

[python path] -m pip install python-docx

Are you using the most recent version of python-docx? (currently 0.8.11). I found that when I used 0.8.10 python couldn't find all the modules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM