when I import docx
I have this error:
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'
How to fix this error (python3.3
, docx 0.2.4)?
wjandrea
27.2k9 gold badges59 silver badges80 bronze badges
asked Mar 31, 2014 at 15:11
1
If you are using python 3x don’t do pip install docx
instead go for
pip install python-docx
It is compatible with python 3.x
Official Documentation available here: https://pypi.org/project/python-docx/
answered May 29, 2017 at 2:21
ArunArun
3,3611 gold badge11 silver badges19 bronze badges
3
When want to use import docx
, be sure to install python-docx, not docx.You can install the module by running pip install python-docx
.
The installation name docx is for a different module
However,
when you are going to import the python-docx module,
you’ll need to run
import docx
, not import python-docx
.
if still you want to use docx module then:
First of all, you will need to make sure that the docx module is installed.
If not then simply run pip install docx
.
If it shows ‘*requirement already satisfied*’
then the solution is :
- Go to the library to find docx.py file,
you’ll need to go to directory where you installed python then Libsite-packages and find docx.py file -
Open docx.py file in text editor and find this code
from exceptions import PendingDeprecationWarning
- Replace the above code with
try:
from exceptions import PendingDeprecationWarning
except ImportError:
pass
- Save the file
- Now you can run import docx module in Python 3.x without any problem
answered Jun 13, 2020 at 16:43
Sameer KhanSameer Khan
3213 silver badges4 bronze badges
- Uninstall docx module with
pip uninstall docx
- Download
python_docx-0.8.6-py2.py3-none-any.whl
file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ - Run
pip install python_docx-0.8.6-py2.py3-none-any.whl
to reinstall docx.
This solved the above import error smoothly for me.
wjandrea
27.2k9 gold badges59 silver badges80 bronze badges
answered Mar 4, 2017 at 2:56
VancentVancent
4775 silver badges16 bronze badges
0
If you’re using python 3.x, Make sure you have both python-docx & docx installed.
Installing python-docx :
pip install python-docx
Installing docx :
pip install docx
answered Apr 26, 2020 at 14:20
KalpitKalpit
1611 silver badge5 bronze badges
In Python 3 exceptions module was removed and all standard exceptions were moved to builtin module. Thus meaning that there is no more need to do explicit import of any standard exceptions.
copied from
answered Apr 10, 2018 at 14:39
sajidsajid
7698 silver badges23 bronze badges
pip install python-docx
this worked for me, try installing with admin mode
answered Dec 22, 2021 at 10:53
The problem, as was noted previously in comments, is the docx module was not compatible with Python 3. It was fixed in this pull-request on github: https://github.com/mikemaccana/python-docx/pull/67
Since the exception is now built-in, the solution is to not import it.
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
dsh
12k3 gold badges33 silver badges51 bronze badges
answered Aug 24, 2015 at 11:46
0
You need to make it work with python3.
sudo pip3 install python-docx
This installation worked for me in Python3 without any further additions.
python3
>> import docx
PS: Note that the ‘pip install python-docx’ or apt-get python3-docx are not useful.
answered Apr 5, 2020 at 14:15
1
I had the same problem, after installing docx module, got a bunch of errors regarding docx, .oxml and lxml…seems that for my case the package was installed in this folder:
C:Program FilesPython3.7Libsite-packages
and I moved it one step back, to:
C:Program FilesPython3.7Lib
and this solved the issue.
Salio
1,01210 silver badges20 bronze badges
answered Jun 27, 2022 at 19:13
python imports exceptions module by itself
comment out import line. it worked for me.
answered Dec 5, 2022 at 18:55
1
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:python26libsite-packagespython_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:python26libsite-packagesdocx-0.2.4-py2.6.eggdocx.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?
asked Oct 16, 2014 at 12:18
4
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:python26libsite-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
.
answered Oct 18, 2014 at 5:44
scannyscanny
26k5 gold badges53 silver badges78 bronze badges
9
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.
answered Jul 4, 2017 at 13:19
Скачиваю библиотеку pip install python-docx
, пытаюсь подключить from docx import Document
как в документации и не видит. У многих была проблема в том, что был установлен старый модуль docx, и всё работало после его удаления, но не у меня.
Что делать? Не нашёл аналогов библиотек для Word документов.
-
Вопрос задан07 дек. 2022
-
719 просмотров
Мужики я разобрался блин блинский) Вообщем терминал в пайчарме через команду pip устанавливал библиотеки в ооочень глубокую папку отдельную от пайчарма. А в встроенном редакторе библиотек пайчарма, они какие-то не такие и старые (googletrans 3.0 например).
Просто закинул из той папки в папку lib проекта. Вопрос как теперь сразу туда скачивать)
Пригласить эксперта
Если не каких ошибок во время инсталяции не выдало, то скорее всего причина в том что устанавливает он ее в другое окружение. Например я сейчас установил данную библиотеку используяpip
и она работает все нормально. если я запускаю pip show python-docx
из окружения которое использует моя IDE то он мне показывает путь и всю информацию, если же я запущу pip show python-docx
из терминала где окружение другое он выдает что данная библиотека не найдена. То есть у вас проблема в окружении (вы установили библиотеку в одно окружение а импортируете из другого)
-
Показать ещё
Загружается…
04 июн. 2023, в 01:35
1500 руб./за проект
04 июн. 2023, в 01:25
40000 руб./за проект
03 июн. 2023, в 23:42
1500 руб./за проект
Минуточку внимания
I am trying something relatively simple but getting this error:
Error: ImportError: No module named docx
Here is my nodeJS script:
const python = require('python-shell');
const shell = new python('../Python/test.py');
let names = ['Hubert', 'Rupert', 'Sherbert', 'Wubbert', 'Paul'];
shell.send(JSON.stringify(names));
shell.on('message', message => console.log(message));
shell.end(message => {console.log(message)});
the python script «test.py»:
import sys, json
from docx import Document
names = json.loads(sys.stdin.readlines()[0])
document = Document('test.docx')
for name in names:
for paragraph in document.paragraphs:
if '$$Name$$' in paragraph.text:
paragraph.text = name
document.save(name+'.docx')
print('completed')
The test.docx is a blank word file that has «$$Name$$» written at the top.
Any ideas? When I run any tests in pyCharm using docx it works fine and does not provide this error. Only when I call through python-shell in my node script.
I have tried setting the options like this:
const python = require('python-shell');
let options = {
pythonPath : '/usr/local/bin/python3'
};
python.defaultOptions = options;
const shell = new python('../Python/test.py');
// rest of code is the same
I verified that this path is where python3 is located on my mac
I have had no luck using these options. All this does is provide a similar error:
Error: docx.opc.exceptions.PackageNotFoundError: Package not found at 'test.docx
If you are using python 3x dont do pip install docx
instead go for
pip install python-docx
It is compatible with python 3.x
Official Documentation available here: https://pypi.org/project/python-docx/
When want to use import docx
, be sure to install python-docx, not docx.You can install the module by running pip install python-docx
.
The installation name docx is for a different module
However,
when you are going to import the python-docx module,
you’ll need to run
import docx
, not import python-docx
.
if still you want to use docx module then:
First of all, you will need to make sure that the docx module is installed.
If not then simply run pip install docx
.
If it shows *requirement already satisfied*
then the solution is :
- Go to the library to find docx.py file,
youll need to go to directory where you installed python then Libsite-packages and find docx.py file -
Open docx.py file in text editor and find this code
from exceptions import PendingDeprecationWarning
- Replace the above code with
try:
from exceptions import PendingDeprecationWarning
except ImportError:
pass
- Save the file
- Now you can run import docx module in Python 3.x without any problem
python – When import docx in python3.3 I have error ImportError: No module named exceptions
- Uninstall docx module with
pip uninstall docx
- Download
python_docx-0.8.6-py2.py3-none-any.whl
file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ - Run
pip install python_docx-0.8.6-py2.py3-none-any.whl
to reinstall docx.
This solved the above import error smoothly for me.