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

Time:12-31

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.

CodePudding user response:

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/

CodePudding user response:

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
  • Related