我正在尝试安装docx包。但是获取以下ImportError
ImportError: cannot import name Document
因此,按照here的建议,我尝试了:
pip install python-docx但出现以下错误(python版本: 2.7.15)
..
..
..
creating build/lib/docx/templates
copying docx/templates/default-header.xml -> build/lib/docx/templates
copying docx/templates/default-settings.xml -> build/lib/docx/templates
copying docx/templates/default-footer.xml -> build/lib/docx/templates
error: can't copy 'docx/templates/default-docx-template': doesn't exist or not a regular file
Command
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import
setuptools,tokenize;__file__='/private/var/folders/0c/v_yb4q7n2h3fg94rlfrr165r0000gn/T/pip-build-ks26RP/python-docx/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n',
'\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/0c/v_yb4q7n2h3fg94rlfrr165r0000gn/T/pip-1SQvtb-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/0c/v_yb4q7n2h3fg94rlfrr165r0000gn/T/pip-build-ks26RP/python-docx/发布于 2019-01-11 07:37:20
在最近发布的v0.8.9中,在某些环境中安装python-docx时出现问题。对于大多数用户来说,安装v0.8.10应该会纠正这个问题。如果安装仍然失败(在某些Linux版本上),已报告更新setuptools以修复它:
$ pip install -U setuptools发布于 2019-01-10 20:02:29
如果您正在尝试使用pip安装软件包,则需要使用sudo,除非您正在安装到用户目录。确实如此;
sudo pip install python-docx你也可以download the package from pypi解压它,cd到untared目录并运行;
sudo python setup.py install可能还需要将setuptools更新到最新版本。
发布于 2019-01-10 21:01:12
对于python2.7,pip安装程序下载需要编译的python-docx源代码,编译过程需要c++构建工具。xcode command line tools为要编译的c++源代码提供了所需的库。要安装xcode command line tools,请使用以下命令:
xcode-select --install在安装之后,再次使用pip xcode command line tools python-docx,这次编译过程应该会完成,没有任何错误,并且您已经在系统上安装了python-docx。
https://stackoverflow.com/questions/54127779
复制相似问题