When import docx in python3.3 I have error ImportError: No module named 'exceptions' - python

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)?

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/

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 \Lib\site-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

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.

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

You may be install docx, not python-docx
You can see this for install python-docx
http://python-docx.readthedocs.io/en/latest/user/install.html#install

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

pip install python-docx
this worked for me, try installing with admin mode

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

I had the same problem, but pip install python-docx worked for me, I'm using python 3.7.1

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.

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 Files\Python3.7\Lib\site-packages
and I moved it one step back, to:
C:\Program Files\Python3.7\Lib
and this solved the issue.

Had faced similar issue and found a work around have posted answer aswell under similar question find its link :https://stackoverflow.com/a/74609166/17385292

python imports exceptions module by itself
comment out import line. it worked for me.

Related

from exceptions import PendingDeprecationWarning ModuleNotFoundError: No module named 'exceptions'

I am trying to create a word document with Python.
I did pip install python-docx in my terminal.
My code looks like this:
from docx import Document
document = Document()
document.save('Test.docx')
I could not create a new document. What am I missing? The existing answer to install python-docx did not work for me.
from exceptions import PendingDeprecationWarning
ModuleNotFoundError: No module named 'exceptions'
you need to install
"python-docx"
by
pip install python-docx
Try pip freeze and check whether the module name is listed or not.
Uninstall docx if installed
pip uninstall docx
Install python-docx
pip install python-docx
Import docx
import docx
Import Document from docx
from docx import Document

I want to check the grammatical mistakes of user data by using NLTK (python)?

I have download language-check package and pasted in D:\Lib\site-packages\nltk but when I type the code over python interpreter as:
import language_check
It gives me an error: no module named language_check.
You need to properly install the package first, for example using
pip install language_check
here are a couple of links to help you:
https://docs.python.org/3/installing/
How do I install Python packages on Windows?

Python cannot import openpyxl

I am running Windows 7 and using Python 2.7.
I have installed openpyxl using easy_install. It looks like the installation was successful. I changed the directory and fired up Python.
>>> import openpyxl
>>>
So, this should mean that Python is able to find openpyxl. However, when I execute a simple test program excell_tutorial1.py and run it, I get the following:
Traceback (most recent call last):
File "C:/Python27/playground/excell_tutorial1.py", line 7, in <module>
from openpyxl import Workbook
ImportError: No module named openpyxl
Very confusing! It could find it in prompt line but not in the program!
import os, sys
the_module ="C:\\Python27\\Lib\\site-packages\\openpyxl-2.3.3-py2.7.egg\\openpyxl"
if the_module not in sys.path:
sys.path.append(the_module)
if the_module in sys.path:
print sys.path.index(the_module)
print sys.path[18]
so, this gives me:
18
C:\Python27\Lib\site-packages\openpyxl-2.3.3-py2.7.egg\openpyxl
Anyone can think of what the problem might be?
Much appreciated
I had the same problem solved using instead of pip or easy install one of the following commands :
sudo apt-get install python-openpyxl
sudo apt-get install python3-openpyxl
The sudo command also works better for other packages.
While not quite what you ran into here (since you state that you are using python 2.7), for those who run into this issue and are using python 3, you may be unintentionally installing to python 2 instead. To force the install to python 3 (instead of 2) use pip3 instead.
See this thread for more info:
No module named 'openpyxl' - Python 3.4 - Ubuntu
Try deleting all openpyxl material from C:\Python27\Lib\site-packages\
Once you do that try reinstalling it using pip. (This what worked for me)
At times this can be a simple permission issue. As it was in my case. I installed it in my local directory with my login.
python ./setup.py install
but some of the other user were not able to import the module.
They were getting this error:
ImportError: No module named openpyxl
Hence I simply gave exe permission to 'others'
chmod -R 755
That solves the problem at least in my case.
Go to the directory where pip is installed, for eg.C:\Python27\Scripts and open cmd (simply type cmd in address bar ). Now run the command "pip install openpyxl". It will install the package itself. Hope this will solve your problem.
Try this:
!pip install openpyxl
I had the same issue on 3.8.2
I found out that python was installed in two locations on my machine (probably py and python, just a guess)
Here:
C:\Users<userAccount>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38
and Here:
C:\Python38
I deleted the one in my C drive and everything is working well now. I would double check to see where your packages are getting installed first, before deleting. Which ever one is being used, keep that one.
For this case, check to see where this package got installed:
C:\Users\<userAccount>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38\site-packages\openpyxl
keep that directory.
What worked for me was to open the terminal as an administrator, cd to the 'scripts' file of where python (different for each version) is stored, and then install using pip:
cd C:\Users\Salfa\AppData\Local\Programs\Python\Python39\Scripts
pip install openpyxl
This resolved the problem for me.

ImportError: No module named 'googlevoice'

python noob here. Just start picking up python few weeks ago and currently need some help. I have 3.3.4 python for windows 7 and I tried running this:
import urllib.request
from googlevoice import Voice
from googlevoice.util import input
import time
File "<pyshell#0>", line 1, in <module>
from googlevoice import Voice
ImportError: No module named 'googlevoice'
so I figured. no big deal, I just need to install the module. I obtained a setup.py file from the link below and ran the file in different directories. Then tried " import googlevoice" but still doesn't work. The github link isn't too helpful, in terms of installing this module. Please help? I think I just have not learned how to install modules properly. Last time it took me a while to install pygame module, but i think it was because of directory issues at first.
https://pygooglevoice.googlecode.com/hg/
http://sphinxdoc.github.io/pygooglevoice/examples.html
To install the PyGoogleVoice, you need to download the whole archive and execute:
python setup.py install
If you have pip install, you can also run pip install pygooglevoice, or easy_install pygooglevoice with EasyInstall, without having to download the source code.

Parse .docx in python 3

I am currently writing a python 3 program that parses through certain docx files and extracts the text and images from them. I have been trying to use docx but it will not import into my program. I have installed lxml, Pillow, and python-docx yet it does not import. When I try to use python-docx from the terminal I cannot use example-extracttext.py or example-makedocument.py which brings me to believe that the installation didn't run properly. Is there a way I can check if this installed correctly or is there a way to get this working properly so I can import it into my project? I am on Ubuntu 13.10.
I recommend you try the latest version of python-docx which is installed like this:
$ pip install python-docx
Documentation is available here: http://python-docx.readthedocs.org/
Installation should result in a message that looks successful. It's possible you'll need to install using sudo to temporarily assume root privileges:
$ sudo pip install python-docx
After installation you should be able to do the following in the Python interpreter:
>>> from docx import Document
>>>
If instead you get something like this, the install didn't go properly:
>>> from docx import Document
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named docx
As you can provide more feedback on your attempts I can elaborate the answer.
Note that after v0.2.x the python-docx package was rewritten. The API of v0.3.x+ is different as well as the package name and repository location. All further development will be on the new version. If you're just starting out with the package going with the latest is probably a good idea as the old one will just be receiving legacy support going forward.
Also, the Python 3 support was added with v0.3.0. Prior versions are not Python 3 compatible.
you can solve your import problem by first uninstalling the existant installation and then install it with pip3. solved my problem with this
pip uninstall python-docx
pip3 install python-docx
Use Command- sudo pip install --pre python-docx for the latest version of python-docx.

Categories