3

I'm trying to use Visual Studio Code (VSC) as IDE for my QGIS plugins with the Python extension, but something doesn't work as expected. I've been reading about the PyCharm config from Gary S. but I couln't apply it to VSC.

Should I use an .env file? What should I set in the settings.json? How to call batch files when VSC starts?

  • All ide's i know, a batch file is used to start them. The starting procedure is analoque to the batch file to start qgis. There are also differences between qgis2 and qgis3. – Andreas Müller Aug 7 '18 at 19:21
4

We didn't want to use a script to open our workspace, so we finally found out how to configure Visual Studio Code through the settings.json file: https://github.com/isogeo/isogeo-plugin-qgis/blob/master/.vscode/settings.json

The requirement is to have QGIS LTR installed with OSGeo4W on the computer. We automated this step with the command-line: https://gist.github.com/Guts/6303dc5eb941eb24be3e27609cd46985

| improve this answer | |
2

Create an empty file named visual_studio_code_for_qgis.bat

Paste this:

@echo off
path %PATH%;C:\Program Files\QGIS 3.2\bin
path %PATH%;C:\Program Files\QGIS 3.2\apps\grass\grass-7.4.1\lib
path %PATH%;C:\Program Files\QGIS 3.2\apps\Qt5\bin
path %PATH%;C:\Program Files\QGIS 3.2\apps\Python36\Scripts

set PYTHONPATH=%PYTHONPATH%;C:\Program Files\QGIS 3.2\apps\qgis\python
set PYTHONHOME=C:\Program Files\QGIS 3.2\apps\Python36   

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

Update paths if necessary.

Run the visual_studio_code_for_qgis.bat

More details can be found here: http://gis-expert.com/wp/2018/10/15/how-to-setup-qgis-3-and-visual-studio-code-plugin-development-windows/

| improve this answer | |
  • I've read your answer and your article (sorry for the delay) but I can't make it work following your instructions. Paths are really different, especially because I've both 2.18 and 3.4 versions installed through the OSGeo4W installer (64 bits). Otherwise, in your article, you should not advise to install packages in the Python system installation, especially with admin level (use of --user option is preferred). For example, PyQt5 is already included into QGIS installation (try to import it into the python-qgis interpreter launched from OSGeo4W Shell). – Guts Jan 17 '19 at 6:15
  • You've chosen to install QGIS differently than Zoran suggests in his instructions. Osgeo4w organizes things differently than if you use QGIS standalone installer which is how Zoran suggests. – cndnflyr Jul 4 '19 at 22:59
1

Here I explain how configure Visual Studio Code for running alone scripts in Python that executes funcions of Qgis.

In the file "Visual_Studio_Code_Qgis\Work_Space_Configuration.code-workspace" is my file configuration that set the envoirment of operatig system.

With this configuration if you run your aplication from Visual Studio code there will be no errors with Python and Qgis.

For use this information: 1.- Goto to the configuration of workspace (Control+) 2.- Select workspace 3.- In right upper square click to Open Configuration Json 4.- Paste my code insight changing Directories.

In my configuration file I have a envoirment, if you don't want or don't have, delete the last lines.

This do the same like file "C:\Program Files\QGIS 3.12\bin\python-qgis.bat".

So if you run this file in CMD, and after that in the same CMD window, you write "set" and enter, you will have a list with the configuration of your system.

| improve this answer | |
0

Try this batch file for an Osgeo4w QGIS install.

https://github.com/frankbroniewski/visual-studio-code-qgis

| improve this answer | |

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.