2

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?

1
  • 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. Nov 30 '18 at 13:47
4

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

1
  • 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 at 14:11
3

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.

1
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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