簡體   English   中英

python-docx無法導入到python

[英]python-docx cannot be imported to python

我正在嘗試安裝python-docx,所以我輸入了cmd

easy_install python-docx

並得到:

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

但是當我打開python並鍵入:

導入docx

我有:

 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.

如何解決此導入錯誤? 什么東西少了?

當您同時安裝了舊版本和新版本的python-docx時,可能會出現此症狀。 我建議您完全卸載兩者,然后使用pip安裝python-docx。 通常,我建議不再使用easy_install

舊版(v0.2.x)的安裝軟件包名稱為“ docx”。 新版本使用名稱“ python-docx”(盡管一旦安裝都導入為“ docx”)。 如果使用pip進行安裝,則卸載/重新安裝應如下所示:

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

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

聽起來您最初使用過easy_install ,所以您可能需要手動卸載,盡管我會先嘗試看看pip是否會幫您完成。 如果沒有,快速搜索python easy_install uninstall將帶您獲得有用的資源。 這可能涉及訪問“ c:\\ python26 \\ lib \\ site-packages \\”,並刪除所有以“ docx”或“ python-docx”開頭的文件或目錄。

這應該使您更進一步。 如果這樣做仍然給您帶來麻煩,請告訴我新的症狀。 如果使用pip則應該能夠在透明的Python安裝上透明安裝。

我也收到相同的“ DLL加載失敗”錯誤。 我這是個愚蠢的錯誤,但是在64位Windows上安裝了32位Python。 未安裝32位版本,已安裝64位版本-問題已解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM