6

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
  • 2
    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
    Commented Jul 20, 2018 at 4:48

2 Answers 2

1

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
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?

1
  • @Luke True. Answer edited. Commented Jul 24, 2018 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.