As I understand it, when QGIS is started from qgis.bat some OSGeo4w specific folder paths are prepended to the OS PATH variable. When I do this and go look in Settings>Options>System>Current environment variables>Path I see

C:\OSGEO4~1\apps\qgis\bin;C:\OSGEO4~1\apps\Python37;C:\OSGEO4~1\apps\Python37\Scripts;C:\OSGEO4~1\apps\qt5\bin;{app};C:\OSGEO4~1\apps\Python27\Scripts;C:\OSGEO4~1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;C:\Program Files\R\R-3.6.1\bin\x64;C:\OSGEO4~1\apps\Python37\lib\site-packages\pywin32_system32;C:\OSGEO4~1\apps\Python37\lib\site-packages\numpy\.libs

If I re-start QGIS using qgis-bin.exe instead and go look at the Path variable, it's the same value. I would have thought that the box would be empty and that the Python console would be interrogating the OS Path-listed instance of Python instead, which on my computer is, in fact, under an ArcGIS Pro folder (this isn't my goal, just part of why I don't understand what qgis.bat is supposed to be doing).

In fact, when I edit the batch file by commenting out the call to py_env.bat, eg.

rem call py3_env.bat

and start again, the Path value is still the same. Why is that?


Revised Answer: The Path settings are stored in the qgis-bin.env file in the bin folder. If you execute the qgis-bin.exe file directly, bypassing the Path settings in the qgis.bat file, QGIS still has the same Path because it is loaded from the .env file. (I don't know what the interaction is between the .env Path and .bat Path, whether one trumps the other or they are merged...)

(I have several other env files, including a qgis-bin-g7.env to go with the qgis-bin-g7.exe, to start QGIS with GRASS 7, and a qgis-ltr-bin.env paired with the qgis-ltr-bin.exe to start QGIS Long Term Release version.)

Original answer where I missed the point of Evan's question, who already understood how the QGIS path variable differs from the system path:

It doesn't make permanent changes global changes to the system environment variable. Rather they are in memory changes confined to processes started within the scope of the qgis.bat file. You can get a feel for the differences if you open a command prompt window by running "OSGeo4W Shell" and another one by Start|Run|cmd, then if you type "path" into each window you will see the OSGeo4W Shell session has quite a different path to the current environment variables displayed in the other command prompt window.

  • Thank you, yes, I get that, but what about the fact that I when I start QGIS from qgis-bin.exe or a modified qgis.bat, that the value is unchanged? The batch file doesn't actually seem to be required. Or maybe it's required only one time and then the value is stored somewhere else? This is not a big deal; it's more a point of confusion that arose when helping a colleague troubleshoot an install.
    – Evan Thoms
    Oct 8 '19 at 17:49
  • Apologies for misunderstanding the question. Yeah, how about that? I just started qgis-bin.exe and Settings | Options | System | Current environment variables shows the same PATH. There are several .env files in the bin directory which contain a number of environment variables, including path, I can only suspect the qgis-bin.exe loads the qgis-bin.env settings when it runs.
    – M Bain
    Oct 8 '19 at 21:49
  • Yup! that's it. I modified qgis-bin.env and saw the change in the QGIS path.
    – Evan Thoms
    Oct 8 '19 at 22:12
  • @M Bain, if you repost your comment as an answer, I will check it (I believe this is the only way to give an answer in the form of a comment the correct credit?)
    – Evan Thoms
    Oct 8 '19 at 22:35
  • @Evan Thoms, thanks Evan, I'm not too fussed about getting the credit - you're the one who did the modification and confirmed. Hopefully my edit will be useful to others.
    – M Bain
    Oct 9 '19 at 5:29

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.