[QGIS-Developer] PyQGIS unavailable at QGIS startup time on OSGeo4W
eric.lemoine at oslandia.com
Wed Oct 2 05:10:29 PDT 2019
On Wed, 2 Oct 2019 12:32:21 +0200
Jürgen E. Fischer <jef at norbit.de> wrote:
> Hi Eric,
> On Wed, 02. Oct 2019 at 11:32:36 +0200, Eric Lemoine wrote:
> > Hi QGIS devs!
> > I need to use a PyQGIS startup script (set via the PYQGIS_STARTUP
> > envvar). And I want to do "import qgis" from that startup script!
> > It works on Linux, because PyQGIS is installed in the system-wide
> > Python environment. So no problem here.
> > But it doesn't work with OSGeo4W. OSGeo4W installs PyQGIS in
> > C:/OSGeo4W64/apps/qgis/python, and that path isn't in sys.path when
> > my startup script is executed.
> > The C:\OSGeo4W64\bin\qgis-bin.env file indeed does not set
> > PYTHONPATH. Likewise, the C:\OSGeo4W64\bin\py3_env.bat file, which
> > C:\OSGeo4W64\bin\qgis.bat includes, has "SET
> > PYTHONPATH=" (PYTHONPATH set to nothing).
> > What do you think? Shouldn't OSGeo4W set PYTHONPATH to
> > "%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%" in py3_env.bat and
> > qgis-bin.env for startup scripts to be able to import and use the
> > qgis module?
> No. py3_env.bat belongs to osgeo4w's python and just switches to
> python3. It shouldn't know about qgis. It's used with everything
> that use python3 (eg. several qgis versions).
> Not sure why PYQGIS_STARTUP is used that early. The python path is
> added shortly after it was referenced:
Yep saw that. And I was wondering too.
> So other platforms should have the same issue.
Except that there's no probleme on Linux, because PyQGIS is installed
globally in the main Python environment.
So Jürgen, would you suggest to change the QGIS code?
More information about the QGIS-Developer