I am a windows 7 user with MS-Office 2016 and python 3.6.
I recently found out that you can write word documents with python.
I looked on how to do that
I installed the docx module:
pip install docx
But whenever i try to import the docx module i get this error:
>>> from docx import Document
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Huzefa\AppData\Local\Programs\Py
in <module>
from exceptions import PendingDeprecationWarn
ModuleNotFoundError: No module named 'exceptions'
I have even tried this but it wont work:
pip install exceptions
I get this error:
ERROR: Could not find a version that satisfies the requirement exceptions (from versions: none)
ERROR: No matching distribution found for exceptions
I thought that maybe this is happening because docx is a python-2 module but it is not. I found it out here
so can someone tell me what i am doing wrong?
I suggest that you can try like this -
$ pip install --pre python-docx
Or you can also try sudo command -
$ sudo pip install --pre python-docx
After that try -
from docx import Document
From here you can find [https://python-docx.readthedocs.io/en/latest/user/install.html][1]
try using:
pip install python-docx
It worked for me!
The problem here is that the name for installation and usage are different:
To install: pip install python-docx
To use: from docx import Document
Install with the correct name (i.e. python-docx) and it shall work.
Related
these are the Error messages I am geeting on running any of my project modules.
Traceback (most recent call last):
File "C:\Users\hsnl\BlockchainCodesTutor\Wallet.py", line 3, in <module>
import Transactions
File "C:\Users\hsnl\BlockchainCodesTutor\Transactions.py", line 2, in <module>
import Signatures
File "C:\Users\hsnl\BlockchainCodesTutor\Signatures.py", line 2, in <module>
import cryptography
ModuleNotFoundError: No module named 'cryptography'
I have already installed the cryptography module and was working perfectly until today I start getting this message that " No module named 'cryptography'".
I have again installed the cryptography as well as pip package but still showing the same error.
There might be loose versions running on your system. Please try the following:
python -m pip uninstall cryptography
python -m pip install cryptography
You can also check out this with python -m to make sure you are not using a loose pip.
You might not have cryptogtaphy installed correctly. I see you are using windows. Open commandline as an administrator and run pip install cryptography again. Enshure that the installation finishes without any errors and consider to restart your python interpreter after installation.
For further help you should post more details like the output of pip and your code leading to the error, so a more detailed answer for your problem can be given.
Try download cryptography whl from here.
Then use pip install cryptography-XXX.whl
For example:
pip install cryptography-3.3.1-cp36-abi3-win_amd64.whl
And now just supports python2.7 and python3.6.
I am trying to use the dnspython in my code but when it gets to the import statement, I get the following error:
>>> import DNS.resolver
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python27\lib\site-packages\DNS\resolver.py", line 31, in <module>
import dns.exception
ImportError: No module named dns.exception
I have tried installing with pip, easy_install and manually from the git repo but nothing seems to do the trick. Any ideas??
Code:
import DNS.resolver
if __name__ == "__main__":
domain = 'hotmail.com'
for x in dns.resolver.query(domain, 'MX'):
print x.to_text()
Another thing you can do to fix problems with this package is to install python-dnspython again using Synaptic. (Whether no having previous problems about duplicity)
Sometimes if you try to install this package using pip could appear some problems like that:
Command python setup.py egg_info failed with error code 1 in
/tmp/pip_build_root/dnspython Storing debug log for failure in
/root/.pip/pip.log
Using Synaptic cleans the old files and install the new ones, from that package. I know this issue is solved but I wanted to add more information about this :)
That's because package and module names are lowercase (see PEP 8). This works just fine :
import dns.resolver
import dns.exception
You should also be careful that none of your own *.py filename conflicts with the dns package. Your *.py file should not be named dns.py. Pay also attention to the *.pyc files.
First, your code should be : import dns.resolver.
There seems to be an issue installing dnspython using pip, you should clone the dnspython repository using git and run the file setup.py as follows:
git clone https://github.com/rthalley/dnspython
cd dnspython\
python setup.py install
If you don't have git installed on your machine, you can just download the repository manually .
I'm trying to do anything considering word document using docx library in python. The problem is, whatever I import, I get error message about 'no attribute'. For eample - Document
from docx import Document
gives output
cannot import name Document
and any try to use Document ends with error
AttributeError: 'module' object has no attribute 'Document'
Any syntax seems to be correct. I'm using docx module version 0.2.4 .
Thanks for all help.
I had a similar problem. I had used pip install docx in my virtual environment. The fix was to pip uninstall docx and then pip install python-docx.
from official documentation
python-docx versions 0.3.0 and later are not API-compatible with prior versions.
so, try to update package or use old api
are you sure you properly installed docx? Because it seems it is not installed.
You should try using pip or easy_install to install it properly.
http://python-docx.readthedocs.org/en/latest/user/install.html
For example, I never installed it and I get this following code error if I try to import it which is pretty much what you get :
Traceback (most recent call last):
File "docx.py", line 1, in <module>
from docx import Document
File "/Users/xxxx/Documents/Python/docx.py", line 1, in <module>
from docx import Document
ImportError: cannot import name Document
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.
i am new to python, on my Mac, when i issue command
User:ihasfriendz user$ python main.py
Traceback (most recent call last):
File "main.py", line 2, in <module>
import json
ImportError: No module named json
I get error on json. how to add this library? i'm using 2.5 (the default came with leopard)
You can also install simplejson.
If you have pip (see https://pypi.python.org/pypi/pip) as your Python package manager you can install simplejson with:
pip install simplejson
This is similar to the comment of installing with easy_install, but I prefer pip to easy_install as you can easily uninstall in pip with "pip uninstall package".
AFAIK the json module was added in version 2.6, see here. I'm guessing you can update your python installation to the latest stable 2.6 from this page.
You can also install json-py from here http://sourceforge.net/projects/json-py/