4

I'm trying to get QGIS API intellisense in VS Code IDE but it doesn't work.

I'm using QGIS 3.4 and Windows 10. I followed the instructions from this link: http://gis-expert.com/wp/2018/10/15/how-to-setup-qgis-3-and-visual-studio-code-plugin-development-windows/

I'm using: VS Code 1.29.1, extensions: Python and PYQT Integration.

This is my bat file:

@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\[username]\AppData\Local\Programs\Python\Python37
path %PATH%;C:\Users\[username]\AppData\Local\Programs\Python\Python37\Scripts

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

Python and PyQT intellisense are ok, QGIS not. Can you help me?

Midavalo
  • 29,696
  • 10
  • 48
  • 104
adlova
  • 51
  • 3
  • If you want to do anything with python3, you should call py3_env.bat in your bat file. There is an example bat/template (python3.bat.tmpl) which shows how to do it. It's in osgeo4w\bin and i was able to call many ide's by changing just the last line. – Andreas Müller Nov 30 '18 at 13:47

2 Answers2

5

this is my .bat for VS Code try with this

@ECHO OFF 

set OSGEO4W_ROOT=D:\OSGeo4W64

@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"

@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%

cd /d %~dp0

SET VSCBIN=D:\Users\fran\AppData\Local\Programs\Microsoft VS Code

call "%VSCBIN%\Code.exe" %*

I hope I help you

Stev_k
  • 6,689
  • 2
  • 34
  • 46
Fran Raga
  • 7,838
  • 3
  • 26
  • 47
  • Thanks! This one is actually working for me (excluding IntelliSense). I've tried the usual "copy the existing batch file and swap whatever path for VS code". Like what Anita Graser had posted for PyCharm, but it doesn't work for me. Python is not able to import qgis package. Perhaps explicitly pointing to OSGeo root does the trick. – pg85 Jan 18 '21 at 14:11
4

I'm running QGIS 3.82 and VSCode 1.37.1 on Windows 10, but had no luck with Fran's .bat file.

I've managed to get intellisense working with just the following entries in a .settings file and starting VSCode without a .bat

{
     "python.pythonPath": "C:\\Program Files\\QGIS 3.8\\apps\\Python37\\python.exe",
     "python.autoComplete.extraPaths": [
         "C:\\Program Files\\QGIS 3.8\\apps\\qgis\\python"]
}

The above paths are for standalone QGIS installation, and obviously would need to be updated for an OSGEO4W install.

  • Thanks @OrdinaryOrange The following works for VSCode and QGIS 3.4 ltr: { "python.pythonPath": "C:\Program Files\QGIS 3.4\apps\Python37\python.exe", "python.autoComplete.extraPaths": ["C:\Program Files\QGIS 3.4\apps\qgis-ltr\python"] } – ian Oct 10 '19 at 19:00
  • When you say "in a .settings file and starting VS Code without a .bat" where do you put the .settings file? In the workspace? in the VS Code install directory? – auslander Nov 18 '21 at 18:13
  • Been a while, but according to my notes the above json should go into the settings.json file of VSCode – OrdinaryOrange Nov 18 '21 at 23:21
  • works like a charm in my VS CODE / QGIS combination: '''{ "workbench.colorTheme": "Visual Studio Dark", "git.autofetch": true, "git.confirmSync": false, "python.defaultInterpreterPath": "C:\Program Files\QGIS 3.32.0\apps\Python39\python.exe", "python.autoComplete.extraPaths": ["C:\Program Files\QGIS 3.32.0\apps\qgis\python"
    ],
    "python.analysis.extraPaths": [
        "C:\\Program Files\\QGIS 3.32.0\\apps\\qgis\\python"
    ]
    

    }'''

    – Riccardo Jul 19 '23 at 12:08