Installing¶
python-docx versions 0.3.0 and later are not API-compatible with prior versions.
python-docx is hosted on PyPI, so installation is relatively simple, and just depends on what installation utilities you have installed.
python-docx may be installed with pip if you have it available:
python-docx can also be installed using easy_install , although this is discouraged:
If neither pip nor easy_install is available, it can be installed manually by downloading the distribution from PyPI, unpacking the tarball, and running setup.py :
python-docx depends on the lxml package. Both pip and easy_install will take care of satisfying those dependencies for you, but if you use this last method you will need to install those yourself.
Как установить библиотеку docx в python
The docx module creates, reads and writes Microsoft Office Word 2007 docx files.
These are referred to as ‘WordML’, ‘Office Open XML’ and ‘Open XML’ by Microsoft.
These documents can be opened in Microsoft Office 2007 / 2010, Microsoft Mac Office 2008, Google Docs, OpenOffice.org 3, and Apple iWork 08.
The module was created when I was looking for a Python support for MS Word .docx files, but could only find various hacks involving COM automation, calling .Net or Java, or automating OpenOffice or MS Office.
The docx module has the following features:
Making documents
Features for making documents include:
- Paragraphs
- Bullets
- Numbered lists
- Document properties (author, company, etc)
- Multiple levels of headings
- Tables
- Section and page breaks
- Images
Editing documents
Thanks to the awesomeness of the lxml module, we can:
- Search and replace
- Extract plain text of document
- Add and delete items anywhere within the document
- Change document properties
- Run xpath queries against particular locations in the document — useful for retrieving data from user-completed templates.
Getting started
Making and Modifying Documents
Use pip or easy_install to fetch the lxml and PIL modules.
Congratulations, you just made and then modified a Word document!
Extracting Text from a Document
If you just want to extract the text from a Word file, run:
Ideas & To Do List
- Further improvements to image handling
- Document health checks
- Egg
- Markdown conversion support
We love forks, changes and pull requests!
- Check out the [HACKING](HACKING.markdown) to add your own changes!
- For this project on github
- Send a pull request via github and we’ll add your changes!
Want to talk? Need help?
License
Licensed under the MIT license
Short version: this code is copyrighted to me (Mike MacCana), I give you permission to do what you want with it except remove my name from the credits. See the LICENSE file for specific terms.
Автоматизированная сборка документа «Текст программы» по ЕСПД с помощью python-docx
Installing¶
python-docx versions 0.3.0 and later are not API-compatible with prior versions.
python-docx is hosted on PyPI, so installation is relatively simple, and just depends on what installation utilities you have installed.
python-docx may be installed with pip if you have it available:
python-docx can also be installed using easy_install , although this is discouraged:
If neither pip nor easy_install is available, it can be installed manually by downloading the distribution from PyPI, unpacking the tarball, and running setup.py :
python-docx depends on the lxml package. Both pip and easy_install will take care of satisfying those dependencies for you, but if you use this last method you will need to install those yourself.
Installing python-docx on pycharm 2017
I am having real trouble with this. Wasted a bunch of hours and just can’t get it figured out. I would appreciate any help.
I have installed python-docx on Pycharm. I run the following code:
And i receive the following error message:
I have seen a number of different explanations . need to update lxml, need to update PIL need to check source folder . and I have not been able to make anything work and it is becoming very frustrating.
I am on a MAC OS X 10.10.5
3 Answers 3
Pretty good chance you have ‘docx’ installed rather than ‘python-docx’. ‘docx’ was the package name for the legacy version, v0.2 and before. It has a completely different API and doesn’t have a Document class. Consequently it gives this exact error. If python-docx just wasn’t installed it would be more like no package named docx .
You can confirm this with pip freeze :
You can only have one installed; they can’t co-exist because the root module name is docx in both cases. Which one gets imported as docx depends on installation order and perhaps other factors; short story is you should get rid of the old one.
Depending on what pip freeze shows you, you’ll want to uninstall docx and install or reinstall python-docx . Safest would be to uninstall them both and then reinstall python-docx .