I am trying to setup PyCharm to work with PyQGIS. I followed this tutorial: https://silverspringenergy.com/using-pycharm-as-an-ide-for-qgis-3-plugin-development-2/. Some files were located elsewhere but in my script I pointed them to the correct path. My script.cmd:

@echo off

call C:\OSGeo4W64\bin\o4w_env.bat
call C:\OSGeo4W64\apps\grass\grass78\etc\env.bat

@echo off
path %PATH%;C:\OSGeo4W64\apps\qgis\bin
path %PATH%;C:\OSGeo4W64\apps\grass\grass78\lib
path %PATH%;C:\OSGeo4W64\apps\Qt5\bin
path %PATH%;C:\OSGeo4W64\apps\Python37\Scripts

set PYTHONPATH=%PYTHONPATH%;C:\OSGeo4W64\apps\qgis\python
set PYTHONHOME=C:\OSGeo4W64\apps\Python37

start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\bin\pycharm64.exe"

The result in PyCharm's python console, after running the script.cmd:

Error processing line 1 of C:\OSGeo4W64\apps\Python37\lib\site-packages\matplotlib-3.1.3-py3.7-nspkg.pth:
  Traceback (most recent call last):
    File "C:\OSGeo4W64\apps\Python37\lib\site.py", line 168, in addpackage
    File "<string>", line 1, in <module>
    File "C:\OSGeo4W64\apps\Python37\lib\importlib\__init__.py", line 51, in <module>
      _w_long = _bootstrap_external._w_long
  AttributeError: module 'importlib._bootstrap_external' has no attribute '_w_long'
Remainder of file ignored
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 5, in <module>
    from _pydev_comm.pydev_rpc import make_rpc_client, start_rpc_server, start_rpc_server_and_make_client
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_rpc.py", line 1, in <module>
    import socket
  File "C:\OSGeo4W64\apps\Python37\lib\socket.py", line 49, in <module>
    import _socket
ImportError: DLL load failed while importing _socket: The specified module could not be found.
Process finished with exit code 1

Any other methods of loading PyQGIS commands without having to startup QGIS first? My current workflow is to load all my scripts via the QGIS Python console, using exec(...), but it is becoming impossible to track down mistakes in my Python code now.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.