python-docx cannot be imported to python

泄露秘密 提交于 2021-02-10 19:41:57

问题


I'm trying to install python-docx so I typed in the cmd

easy_install python-docx

and got:

Searching for python-docx
Best match: python-docx 0.7.4
Processing python_docx-0.7.4-py2.6.egg
python-docx 0.7.4 is already the active version in easy-install.pth

Using c:\python26\lib\site-packages\python_docx-0.7.4-py2.6.egg
Processing dependencies for python-docx
Finished processing dependencies for python-docx

but when I open python and type:

import docx

I got:

 File "c:\python26\lib\site-packages\docx-0.2.4-py2.6.egg\docx.py", line 17, in <
module>
    from lxml import etree
ImportError: DLL load failed: The specified procedure could not be found.

How can I solve this import error? what is missing?


回答1:


This symptom can arise when you have both a legacy version and a new version of python-docx installed. I recommend you uninstall both completely and then install python-docx using pip. In general I recommend avoiding the use of easy_install anymore.

The legacy versions (v0.2.x) have the install-package name 'docx'. The new version uses the name 'python-docx' (although both import as 'docx' once installed). If you installed with pip doing the uninstall/reinstall would look something like this:

$ pip freeze
...
docx
...
python-docx
...

$ pip uninstall docx
...
$ pip uninstall python-docx
...
$ pip install python-docx
...

It sounds like you used easy_install originally, so you might need to uninstall manually, although I would try first and see if pip will get it done for you. If not, a quick search on python easy_install uninstall will lead you to useful resources. It might involve visiting "c:\python26\lib\site-packages\" and removing any files or directories that start with 'docx' or 'python-docx'.

This should get you further along. If it still gives you trouble after doing this, let me know the new symptoms. You should be able to install pretty transparently on an uncorrupted Python installation if you use pip.




回答2:


I too was getting same 'DLL load failed' error. Stupid mistake on my part, but had installed 32 bit Python on to 64 bit Windows. Un-installed 32 bit version, installed 64 bit version - problem sorted.



来源:https://stackoverflow.com/questions/26404228/python-docx-cannot-be-imported-to-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!