Bij het importeren van docx in python3.3 krijg ik een foutmelding ImportError: Geen module met de naam ‘uitzonderingen’

wanneer ik docximporteer, krijg ik deze fout:

 File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/docx-0.2.4-py3.3.egg/docx.py", line 30, in <module>
    from exceptions import PendingDeprecationWarning
ImportError: No module named 'exceptions'

Hoe kan ik deze fout oplossen (python3.3, docx 0.2.4)?


Antwoord 1, autoriteit 100%

Als je python 3x gebruikt, doe dan niet pip install docxmaar ga voor

pip install python-docx 

Het is compatibel met python 3.x

Officiële documentatie hier beschikbaar: https://pypi.org/project/python-docx/


Antwoord 2, autoriteit 9%

Als je import docxwilt gebruiken, zorg er dan voor dat je python-docxinstalleert, niet docx. kan de module installeren door pip install python-docxuit te voeren.

De installatienaam docxis voor een andere module
Echter,

wanneer u de python-docx-module gaat importeren,
je moet rennen
import docx, niet import python-docx.

als je nog steeds de docx-module wilt gebruiken,:

Allereerst moet u ervoor zorgen dat de module docxis geïnstalleerd.
Zo niet, voer dan gewoon pip install docxuit.
Als het toont ‘*vereiste al voldaan*’
dan is de oplossing:

  1. Ga naar de bibliotheek om het bestand docx.pyte vinden,
    je moet naar de map gaan waar je python hebt geïnstalleerd en vervolgens \Lib\site-packages\ en het docx.py-bestand
  2. zoeken

  3. Open het bestand docx.pyin de teksteditor en zoek deze code

    from exceptions import PendingDeprecationWarning
    
  4. Vervang bovenstaande code door
try:
    from exceptions import PendingDeprecationWarning
except ImportError:
    pass
  1. Bewaar het bestand
  2. Je kunt nu zonder enig probleem de module import docxin Python 3.x uitvoeren

Antwoord 3, autoriteit 8%

  1. Deïnstalleer de docx-module met pip uninstall docx
  2. Download het bestand python_docx-0.8.6-py2.py3-none-any.whlvan http://www.lfd.uci.edu/~gohlke/pythonlibs/
  3. Voer pip install python_docx-0.8.6-py2.py3-none-any.whluit om docx opnieuw te installeren.

Dit loste de bovenstaande importfout probleemloos voor mij op.


Antwoord 4, autoriteit 4%

Als je python 3.x gebruikt, zorg er dan voor dat je zowel python-docx& docxgeïnstalleerd.

Python-docx installeren:

pip install python-docx 

Docx installeren:

pip install docx

Antwoord 5, autoriteit 4%

Je mag docxinstalleren, niet python-docx

U kunt dit zien voor het installeren van python-docx

http://python-docx.readthedocs.io/ nl/latest/user/install.html#install


Antwoord 6, autoriteit 3%

In Python 3 is de uitzonderingsmodule verwijderd en zijn alle standaarduitzonderingen verplaatst naar de ingebouwde module. Dit betekent dat het niet meer nodig is om standaarduitzonderingen expliciet te importeren.

gekopieerd van


Antwoord 7

Het probleem, zoals eerder opgemerkt in opmerkingen, is dat de docx-module niet compatibel was met Python 3. Het werd opgelost in dit pull-request op github: https://github.com/mikemaccana/python-docx/pull/67

Aangezien de uitzondering nu is ingebouwd, is de oplossing om deze niet te importeren.

docx.py
@@ -27,7 +27,12 @@
 except ImportError:
     TAGS = {}
-from exceptions import PendingDeprecationWarning
+# Handle PendingDeprecationWarning causing an ImportError if using Python 3
+try:
+    from exceptions import PendingDeprecationWarning
+except ImportError:
+    pass
+
 from warnings import warn
 import logging

Antwoord 8

Ik had hetzelfde probleem, maar pip install python-docxwerkte voor mij, ik gebruik python 3.7.1


Antwoord 9

Je moet het laten werken met python3.

                    sudo pip3 install python-docx

Deze installatie werkte voor mij in Python3 zonder verdere toevoegingen.

            python3
             >> import docx

PS: Merk op dat de ‘pip install python-docx’ of apt-get python3-docx niet nuttig zijn.


Antwoord 10

pip install python-docx

dit werkte voor mij, probeer te installeren met beheerdersmodus

Other episodes