I installed python-docx and when importing docx, I get some errors. I am using a MAC, Python 3.11, PyCharm. Does anyone knows how to solve this? Btw, I am a beginner in coding and in Python... please explain as you would to a four year old XD.
I don't know if it is a Mac error, or an lxml error, or this file error: etree.cpython-311-darwin.so... any help will be much appreciated.
Here are the commands and errors I get:
import docx
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
^^^^^^
File "<input>", line 1, in <module>
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../venv/lib/python3.11/site-packages/docx/__init__.py", line 3, in <module>
from docx.api import Document # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../venv/lib/python3.11/site-packages/docx/api.py", line 14, in <module>
from docx.package import Package
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../venv/lib/python3.11/site-packages/docx/package.py", line 9, in <module>
from docx.opc.package import OpcPackage
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../venv/lib/python3.11/site-packages/docx/opc/package.py", line 9, in <module>
from docx.opc.part import PartFactory
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../venv/lib/python3.11/site-packages/docx/opc/part.py", line 12, in <module>
from .oxml import serialize_part_xml
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../venv/lib/python3.11/site-packages/docx/opc/oxml.py", line 12, in <module>
from lxml import etree
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: dlopen(/Users/.../venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so, 0x0002): tried: '/Users/.../venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so' (code signature in <C969C6B5-4EEB-3E5B-92FB-9F4148B6A87D> '/Users/.../venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so' not valid for use in process: Trying to load an unsigned library), '/System/Volumes/Preboot/Cryptexes/OS/Users/.../venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so' (no such file), '/Users/.../venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so' (code signature in <C969C6B5-4EEB-3E5B-92FB-9F4148B6A87D> '/Users/.../venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so' not valid for use in process: Trying to load an unsigned library)
I tried to import docx to manipulate Words files. I installed python-docx instead of docx since I am running Python 3.11.