3

I'm using the command : pyinstaller -w -F main.py

And I got this message when I tried to run the exe file:

Traceback (most recent call last):
File "main.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "ms_word.py", line 2, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "docx_init_.py", line 3, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "docx\api.py", line 14, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "docx\package.py", line 9, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "docx\opc\package.py", line 9, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "docx\opc\part.py", line 12, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "docx\opc\oxml.py", line 12, in <module>
File "src\lxml\etree.pyx", line 74, in init lxml.etree
ImportError: cannot import name _elementpath

It seems it is related with docx import, since this error doesn't appear when I disabled docx from my code.

Does anybody knows how to solve this problem?
Thank you.

Nachomic
  • 31
  • 2
  • Perhaps similar to this problem: https://stackoverflow.com/questions/22133313/why-am-i-getting-this-importerror – scanny Dec 06 '21 at 05:07

1 Answers1

1

I encountered same problem when using Pycharm with Python 3.8.10. I tried to solve it but no solution found. However, the same program when used with system interpreter version 3.9.6 and packed with pyinstaller on system cmd produced no errors. In general, it seems when packed in Pycharm it produces many errors (even when the user's Python versions are the same as the system's Python version).

Before encountering this error, I got stuck in the pythoncom module isn't in frozen sys.path error.

Just add --hidden-import lxml._elementpath in pyinstaller ... line.

mrcendre
  • 1,053
  • 2
  • 15
  • 28
Muddybeast
  • 31
  • 4