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
TomazicM
  • 25,601
  • 22
  • 29
  • 39
Artec
  • 982
  • 5
  • 14

2 Answers2

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

Fran Raga
  • 7,838
  • 3
  • 26
  • 47
1

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.