How to setup QGIS 3 and Visual Studio Code plugin development (Windows)

  • Install QGIS 3. In our case, installation directory will be C:\Program Files\QGIS 3.4
  • Install Python. In our case, installation directory will be C:\Users\Zoran\AppData\Local\Programs\Python\Python37-32
  • Run Command Prompt as Administrator. Navigate to the Python directory:
>cd C:\Users\Zoran\AppData\Local\Programs\Python\Python37-32
  • Upgrade PIP (PIP is a package manager for Python packages):
>python -m pip install --upgrade pip
>python -m pip install pb_tool
  • Install pyqt5 (PyQt5 is a comprehensive set of Python bindings for Qt v5)
>pip3 install pyqt5
  • Open Notepad and create visual_studio_code_for_qgis.bat file with this content:
@echo off
path %PATH%;C:\Program Files\QGIS 3.4\bin
path %PATH%;C:\Program Files\QGIS 3.4\apps\grass\grass-7.4.2\lib
path %PATH%;C:\Program Files\QGIS 3.4\apps\Qt5\bin
path %PATH%;C:\Program Files\QGIS 3.4\apps\qgis\python\qgis\PyQt
path %PATH%;C:\Program Files\QGIS 3.4\apps\Python37\Scripts
set PYTHONPATH=%PYTHONPATH%;C:\Program Files\QGIS 3.4\apps\qgis\python
set PYTHONHOME=C:\Users\Zoran\AppData\Local\Programs\Python\Python37-32
path %PATH%;C:\Users\Zoran\AppData\Local\Programs\Python\Python37-32\Scripts

start "VisualCode QGIS" /B "C:\Users\Zoran\AppData\Local\Programs\Microsoft VS Code\Code.exe" %*

Update paths if necessary.

  • Open Notepad and create py_qgis.bat file with this content:
@echo off
path %PATH%;C:\Program Files\QGIS 3.4\bin
path %PATH%;C:\Program Files\QGIS 3.4\apps\grass\grass-7.4.2\lib
path %PATH%;C:\Program Files\QGIS 3.4\apps\Qt5\bin
path %PATH%;C:\Program Files\QGIS 3.4\apps\qgis\python\qgis\PyQt
path %PATH%;C:\Program Files\QGIS 3.4\apps\Python37\Scripts
set PYTHONPATH=%PYTHONPATH%;C:\Program Files\QGIS 3.4\apps\qgis\python
set PYTHONHOME=C:\Users\Zoran\AppData\Local\Programs\Python\Python37-32
path %PATH%;C:\Users\Zoran\AppData\Local\Programs\Python\Python37-32\Scripts

cmd.exe

Update paths if necessary.

  • To start Visual Studio Code that recognizes QGIS API, run visual_studio_code_for_qgis.bat file.
  • If you want to run Command Prompt commands, such as pb_tool or PyQGIS, then run the py_qgis.bat file.
If you get an error in Visual Studio Code about PyQt5 import, add this in Visual Studio Settings:
 
"python.linting.pylintArgs": [

"--extension-pkg-whitelist=PyQt5, qgis"

]

2 thoughts on “How to setup QGIS 3 and Visual Studio Code plugin development (Windows)

  • November 27, 2018 at 3:54 pm
    Permalink

    I followed your instructions but the QGIS API intellisense in VS Code is not working!
    Python and PyQT intellisense work.
    I have Win 10, QGIS 3.4, VS Code 1.29.1, Python extension, PYQT Integration extension.
    My .bat file is:
    @echo off
    path %PATH%;C:\PROGRA~1\QGIS3~1.4\bin
    path %PATH%;C:\PROGRA~1\QGIS3~1.4\apps\qgis\bin
    path %PATH%;C:\PROGRA~1\QGIS3~1.4\apps\grass\grass-7.4.2\lib
    path %PATH%;C:\PROGRA~1\QGIS3~1.4\apps\Qt5\bin
    path %PATH%;C:\PROGRA~1\QGIS3~1.4\apps\qgis\python\qgis\PyQt
    path %PATH%;C:\PROGRA~1\QGIS3~1.4\apps\Python37\Scripts
    set PYTHONPATH=%PYTHONPATH%;C:\PROGRA~1\QGIS3~1.4\apps\qgis\python
    set PYTHONHOME=C:\Users\[myusername]\AppData\Local\Programs\Python\Python37
    path %PATH%;C:\Users\[myusername]\AppData\Local\Programs\Python\Python37\Scripts

    start “VisualCode QGIS” /B “C:\Users\[myusername]\AppData\Local\Programs\Microsoft VS Code\Code.exe” %*

    I also tried in Eclipse IDE (following QGIS Cookbook instructions) but QGIS intellisense doesn’t work there either.
    Do you have any suggestion?

    Reply
    • January 10, 2019 at 5:56 pm
      Permalink

      Did you try to replace ;C:\PROGRA~1\QGIS3~1.4\ with a full path?
      for example: C:\Program Files\QGIS 3.4 ?

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *