5

I have installed the newest QGIS and downloaded python-docx from this link python-docx . I haven't installed separately a different version of python. Is it possible to integrate this package of python-docx to work with QGIS (Windows version) ?

  1. I looked at this site Installing Third-party Python Modules in QGIS (Windows)
  2. After changing this section call(['easy_install', 'lxml']) to call(['easy_install', 'python-docx']) and run code in QGIS Python console I've got an error : enter image description here
4
  • Did you know how to install a Python module ?
    – gene
    Commented May 21, 2016 at 15:31
  • I did it on Virtual machine with portable python (and it works but only with python console). I don't know how to install this python module with QGIS.
    – Artec
    Commented May 22, 2016 at 9:39
  • There are many answers in GIS SE, look for example in QGIS docutils install (path,pythonpath,pythonhome)
    – gene
    Commented May 22, 2016 at 14:53
  • @gene I update my question. The problem is still not resolved.
    – Artec
    Commented May 22, 2016 at 18:49

2 Answers 2

2

you should use the following code, in osgeo shell(just check python 2.7 is not your default python in shell), or from pycharm terminal(after configuring pycharm to know your qgis 3 python following Setting up PyCharm for PyQGIS and Qt)

python3 -m pip install python-docx

just notice that the qgis 3 python console intellisense will not be updated, but in pycharm, yes, how ever the module import works for both.

2

To install this python module or any other you can follow this flow.

  1. Create a .bat (py3_qgis.bat) with this lines, (change your QGIS 3 path)

    @ECHO OFF 
    
    :: QGIS path
    set OSGEO4W_ROOT=D:\OSGeo4W64 
    
    set PATH=%OSGEO4W_ROOT%\bin;%PATH%
    set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
    
    @echo off
    call %OSGEO4W_ROOT%\bin\o4w_env.bat
    call qt5_env.bat
    call py3_env.bat
    @echo off
    path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
    
    cd /d %~dp0
    
    start cmd
    
  2. In the cmd opened by the previous script, write this:

    python3 -m pip install python-docx
    
  3. Open QGIS and import the module:

    from docx import Document
    

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.