I'm referring to this post:
Why does QGIS 3.2 "native:extractvertices" algorithm not work properly in standalone script?
as part on creating startup file py3-env.bat
for opening PyCharm with PyQGIS works:
@ECHO OFF
set OSGEO4W_ROOT=C:\OSGeo4W64
@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
call "%OSGEO4W_ROOT%\bin\py3_env.bat"
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set GDAL_FILENAME_IS_UTF8=YES
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition with Anaconda plugin 2020.1\bin\pycharm64.exe"
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\lib\site-packages;%PYTHONPATH%
set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis
cd /d %~dp0
::python3 scratch.py
::pause
start "PyCharm aware of QGIS" /B %PYCHARM% %*
I have:
QGIS 3.12.1 installed in: C:\OSGeo4W64
PyCharm 2020.1 installed in: C:\Program Files\JetBrains\PyCharm Community Edition with Anaconda plugin 2020.1\
After loading PyCharm the interpreter looks like this:
Now I just would like to run a simple test script like:
#native:extractvertices
import sys
from qgis.core import (
QgsApplication,
QgsProcessingFeedback,
QgsVectorLayer
)
from qgis.analysis import QgsNativeAlgorithms
QgsApplication.setPrefixPath(r'C:\OSGeo4W64\apps\qgis', True)
qgs = QgsApplication([], False)
qgs.initQgis()
sys.path.append(r'C:\OSGeo4W64\apps\qgis\python\plugins')
import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
layer = QgsVectorLayer(r"D:\test_pygis\lines.shp", 'my layer', 'ogr')
output = r"D:\test_pygis\verticles.shp"
params = {
'INPUT': layer,
'OUTPUT': output,
}
feedback = QgsProcessingFeedback()
res = processing.run("native:extractvertices", params, feedback=feedback)
print(res)
First the processing module is not found:
If I try to run the code the second well know error appears in the Python console:
qt.qpa.plugin: Could not find the Qt platform plugin "windows" in "C:\OSGEO4~1\apps\Qt5\plugins\platforms"
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.