wanneer ik docx
importeer, 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 docx
maar 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 docx
wilt gebruiken, zorg er dan voor dat je python-docxinstalleert, niet docx. kan de module installeren door pip install python-docx
uit 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 docx
uit.
Als het toont ‘*vereiste al voldaan*’
dan is de oplossing:
- 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 -
Open het bestand docx.pyin de teksteditor en zoek deze code
from exceptions import PendingDeprecationWarning
- Vervang bovenstaande code door
zoeken
try:
from exceptions import PendingDeprecationWarning
except ImportError:
pass
- Bewaar het bestand
- Je kunt nu zonder enig probleem de module import docxin Python 3.x uitvoeren
Antwoord 3, autoriteit 8%
- Deïnstalleer de docx-module met
pip uninstall docx
- Download het bestand
python_docx-0.8.6-py2.py3-none-any.whl
van http://www.lfd.uci.edu/~gohlke/pythonlibs/ - Voer
pip install python_docx-0.8.6-py2.py3-none-any.whl
uit 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 docx
installeren, 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.
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-docx
werkte 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