1 year ago
#363305
Simon Andersen
Setting up QGIS-related .bat files for standalone Python script in PyCharm - errors
I have been trying alot of different solutions for the problem, but keep getting the same error. And it seems that Python is perhaps looking into the "wrong" python directory - or something.
However, I have been following the stated in https://plugins.qgis.org/planet/tag/pycharm/ where I have created the following bat-file:
SET OSGEO4W_ROOT=C:\OSGeo4W64
SET QGISNAME=qgis
SET QGIS=%OSGEO4W_ROOT%\apps%QGISNAME%
SET QGIS_PREFIX_PATH=%QGIS%
SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\bin\pycharm64.exe"
CALL %OSGEO4W_ROOT%\bin\o4w_env.bat
SET PATH=%PATH%;%QGIS%\bin
SET PYTHONPATH=%QGIS%\python;%PYTHONPATH%
start "PyCharm aware of QGIS" /B %PYCHARM% %*"
Here I have changed the PYCHARM
path to match mine and the OSGEO4W_ROOT
This gives me the following errors when PyCharm opens:
Python path configuration:
PYTHONHOME = 'C:\OSGEO4~1\apps\Python27'
PYTHONPATH = 'C:\OSGeo4W64\apps\qgis\python;C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\third_party\thriftpy;C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\pydev'
program name = 'C:\Users\Simon\AppData\Local\Programs\Python\Python39\python.exe'
isolated = 0
environment = 1
user site = 1
import site = 1
sys.`_`base_executable = 'C:\Users\Simon\AppData\Local\Programs\Python\Python39\python.exe'_
sys.base_prefix = 'C:\OSGEO4~1\apps\Python27'
sys.base_exec_prefix = 'C:\OSGEO4~1\apps\Python27'
sys.platlibdir = 'lib'
sys.executable = :\Users\Simon\PycharmProjects\QGIS_test\venv\Scripts\python.exe'
sys.prefix = 'C:\OSGEO4~1\apps\Python27'
sys.exec_prefix = 'C:\OSGEO4~1\apps\Python27'
sys.path = [
'C:\OSGeo4W64\apps\qgis\python',
'C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\third_party\thriftpy',
'C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\pydev',
'C:\Users\Simon\AppData\Local\Programs\Python\Python39\python39.zip',
'C:\OSGEO4~1\apps\Python27\DLLs',
'C:\OSGEO4~1\apps\Python27\lib',
'C:\Users\Simon\AppData\Local\Programs\Python\Python39',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized`
File "C:\OSGEO4~1\apps\Python27\lib\encodings_`_`init`_`.py",
line 123
raise CodecRegistryError,
^SyntaxError: invalid syntax
Current thread 0x0000222c (most recent call first):
<no Python frame>
To me it seems that the environmental variables are off, however, I have already tried to set these in the control panel.
Does anyone else experience the same, or do you have any suggestions on how to solve this problem.
Thank you in advance,
For clarification. I have windows 10, QGIS 3.18 installed in OSGeo4W64, and PyCharm Community Edition 2021.3.3 installed
/Simon
python
pycharm
qgis
pyqgis
0 Answers
Your Answer