I want to set the environemnt that works in visual studio 2022 (for Python) with Windows 10 for pyqgis 3.9.
I found the solution creating a “set_qgis_env.bat” with this content.
set PATH=C:ProgrammiACQGIS3.28appsPython39;%PATH%
set PYTHONPATH=C:ProgrammiACQGIS3.28appsqgis-ltrpython;C:ProgrammiACQGIS3.28appsqgis-ltrpythonplugins;C:ProgrammiACQGIS3.28appsQt5plugins;C:ProgrammiACQGIS3.28appsPython39Libsite-packages
rem modify the path if necessary
"C:Program FilesMicrosoft Visual Studio2022ProfessionalCommon7IDEdevenv.exe"
If I run manually “set_qgis_env.bat” visual studio open automatically with the right environment.
I am not completely happy with this solution because I don’t want to run the “set_qgis_env.bat” manually, but I want that when I open visual studio (sln) it run automatically. Visual Studio must be able to run the bat file alone when I open it.
I thounght to have the solution. I added on the visual studio 2022 solution and with property>>>Debug>>>Script Argument I added the path of “set_qgis_env.bat”
enter image description here
It does not work because when I close and reopen the visual studio solution has no environment.
I know that there is a second solution: to add “enviroment variables” alone.
enter image description here
Again, it does not work!
Is there a problem of semantic for PATH and PYTHONPATH? No, because “set_qgis_env.bat” manually works. Furthermore if I add the environment variable in windows with the same paths of “set_qgis_env.bat”, when I open visual studio the environment is OK, but it is not my wished solution because after I have problem with the script in the python console of QGIS.enter image description here
Question: What is the problem and how can I set the environment every time that I open visual studio 2022?
Simon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.