3

I want to work with PyQGIS Python 3 using QGIS 3.2 standalone install. I created a simple batch file to work with PyQGIS but I have some errors.

Here's the batch file:

@echo off
SET OSGEO4W_ROOT=C:\Program Files\QGIS 3.2

call "%OSGEO4W_ROOT%"\bin\o4w_env
call "%OSGEO4W_ROOT%"\apps\grass\grass-7.4.1\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-7.4.1\lib
path %PATH%;%OSGEO4W_ROOT%\apps\Qt5\bin
path %PATH%;%OSGEO4W_ROOT%\apps\Python36\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python36


SET PYCHARM="C:\Program Files\JetBrains\PyCharm 2018.1.4\bin\pycharm.exe
start "PyCharm aware of QGIS" /B %PYCHARM% %*

Error is:

  File "C:\PROGRA~1\QGIS3~1.2\apps\Python36\lib\site.py", line 177
    file=sys.stderr)
        ^
SyntaxError: invalid syntax
  • 1
    Sounds like python 2.7 is getting called instead of python3. Update your batch script to call py3_env. Not sure where it is, I don't have access to osgeo4w currently, probably somewhere like call "%OSGEO4W_ROOT%"\bin\py3_env – user2856 Jul 20 '18 at 4:48
0

The problem may be caused by incorrect PyCharm setup, check this answer: Why does QGIS 3.2 "native:extractvertices" algorithm not work properly in standalone script?

  • @Luke True. Answer edited. – Mr. Che Jul 24 '18 at 12:33
0

Jessie, I suspect there may be a problem with this line in your batch file:

SET OSGEO4W_ROOT=C:\Program Files\QGIS 3.2

try setting it to your OSGeo4W64 root folder like below:

SET OSGEO4W_ROOT=C:\OSGeo4W64

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.