Configuración de PyCharm para trabajar con bibliotecas QGIS
He estado siguiendo varias publicaciones y tutoriales, incluidas las publicaciones de Anita Graser, Anita Graser yhttps://gis.stackexchange.com/questions/302774/ mientras trato de configurar mi instalación de PyCharm para acceder y trabajar con las bibliotecas QGIS en mi instalación OSGeo4W64 QGIS 3.14
He creado los archivos pygis.cmd y pycharm.cmd necesarios y parecen hacer lo que deberían. Mi pycharm.cmd lanza PyCharm con éxito
> @echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\bin\qt5_env.bat
call "%OSGEO4W_ROOT%"\bin\py3_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass78\etc\env.bat
@echo off
rem path %PATH%;%OSGEO4W_ROOT%\apps\qgis
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass78\lib
path %PATH%;C:\OSGeo4W64\apps\Qt5\bin
rem path %PATH%;C:\OSGeo4W64\apps\qgis\python\plugins
path %PATH%;C:\OSGeo4W64\apps\Python37\Scripts
rem path %PATH%;C:\OSGeo4W\apps\Python37
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set PATH=C:\Program Files\Git\bin;%PATH%
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\Qt5\plugins
start "PyCharm aware of QGIS" /B "C:\Users\b8060507\AppData\Local\JetBrains\PyCharm Community Edition 2019.3.3\bin\pycharm64.exe"
Sin embargo, a pesar de seguir https://gis.stackexchange.com/questions/302774/ Sigo apareciendo este mensaje de error

Estoy seguro de haber configurado correctamente la ruta del complemento Qt, que la publicación 302774 recomienda incluir:
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
en el archivo pycharm.cmd
¿Alguien puede ofrecer algún consejo sobre dónde podría estar yendo mal? Espero que 'Ben W', entre otros, vea esta pregunta, ya que su consejo ayudó a otros en la publicación 302774, pero no me está funcionando en 2020. Entonces, ¿tal vez haya otras anomalías en la configuración que ahora se requieren para versiones posteriores de QGIS?
Respuestas
La ruta de su complemento Qt se ve bien. A continuación se muestra el archivo por lotes que estoy usando actualmente. He probado esto con un QGIS 3.14.15 recién instalado (instalación de OSGeo4W) y no obtengo ningún error. Puede probarlo y ver si funciona para usted.
* Nota: He estado usando PyScripter en lugar de PyCharm por un tiempo, pero realmente no debería hacer ninguna diferencia. Simplemente cambie la última línea para iniciar PyCharm en su lugar.
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\bin\qt5_env.bat
call "%OSGEO4W_ROOT%"\bin\py3_env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;C:\OSGeo4W64\apps\Qt5\bin
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
start "PyScripter aware of QGIS" /B "C:\Program Files\PyScripter\PyScripter.exe"
Al iniciar PyScripter con este archivo por lotes, puedo ejecutar lo siguiente sin errores.
Para probar las bibliotecas de QGIS:
from qgis.core import *
QgsApplication.setPrefixPath("C:/OSGeo4W/apps/qgis", True)
qgs = QgsApplication([], False)
qgs.initQgis()
qgs.exitQgis()
Y para probar PyQt:
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
class MyDialog(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setGeometry(250, 250, 500, 350)
def main():
app = QApplication(sys.argv)
w = MyDialog()
w.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()