ImportError: cannot import name _elementpath 终极解决办法

在使用pyinstaller打包含有python-docx包的软件时出现以下错误:Failled to execute script XXX due to unhandled exception: cannot import name _elementpath

ImportError: cannot import name _elementpath 终极解决办法_第1张图片

经过查询资料后发现原来是lxml这个文件没有打包进文件,所以在使用pyinstaller时增加以下内容:

pyinstaller -F -w XXX.py --hidden-import lxml._elementpath

这样再次打包时就不会出错了。本人使用的是python 3.80, 有网友测试使用 python 3.9.6 打包后不会出现同样的错误。所以要想不出错,就用高版本的python

参考文章:python - pyinstaller: ImportError: cannot import name _elementpath - Stack Overflow

你可能感兴趣的:(python,python,pycharm,开发语言)