1

I have built QGIS 3.2.0 with the release code downloaded from GitHub, using CMake and Visual Studio 2017. Basically I followed the instructions in INSTALL file. When I run QGIS.exe, it shows:

Couldn't load PyQGIS.
Python support will be disabled.


Traceback (most recent call last):
  File "", line 1, in 
ModuleNotFoundError: No module named 'qgis'


Python version:
3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]

QGIS version:
3.2.0-Bonn 'Bonn', exported

Python path:
['I:/OSGeo4W64/apps/qgis/./python', 'H:/Users/Aurus/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python', 'H:/Users/Aurus/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python/plugins', 'I:/OSGeo4W64/apps/qgis/./python/plugins', 'I:\\OSGeo4W64\\bin\\python36.zip', 'I:\\OSGeo4W64\\apps\\Python36\\DLLs', 'I:\\OSGeo4W64\\apps\\Python36\\lib', 'I:\\qgis\\bin', 'I:\\OSGeo4W64\\apps\\Python36', 'I:\\OSGeo4W64\\apps\\Python36\\lib\\site-packages']

And:

An error occurred during execution of following code:
qgis.utils.uninstallErrorHook()


Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'qgis' is not defined


Python version:
3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]

QGIS version:
3.2.0-Bonn 'Bonn', exported

Python path:
['I:/OSGeo4W64/apps/qgis/./python', 'H:/Users/Aurus/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python', 'H:/Users/Aurus/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python/plugins', 'I:/OSGeo4W64/apps/qgis/./python/plugins', 'I:\\OSGeo4W64\\bin\\python36.zip', 'I:\\OSGeo4W64\\apps\\Python36\\DLLs', 'I:\\OSGeo4W64\\apps\\Python36\\lib', 'I:\\qgis\\bin', 'I:\\OSGeo4W64\\apps\\Python36', 'I:\\OSGeo4W64\\apps\\Python36\\lib\\site-packages']

I place a qgis.env on the binary directory with following contents, instead of modifying system environment variables:

PATH=I:\OSGeo4W64\apps\qgis\bin;I:\OSGeo4W64\apps\Python36;I:\OSGeo4W64\apps\Python36\Scripts;I:\OSGeo4W64\apps\qt5\bin;I:\OSGeo4W64\apps\Python27\Scripts;I:\OSGeo4W64\bin;H:\WINDOWS\system32;H:\WINDOWS;H:\WINDOWS\system32\WBem
GDAL_DATA=I:\OSGeo4W64\share\gdal
GDAL_DRIVER_PATH=I:\OSGeo4W64\bin\gdalplugins
GDAL_FILENAME_IS_UTF8=YES
GEOTIFF_CSV=I:\OSGeo4W64\share\epsg_csv
JPEGMEM=1000000
OSGEO4W_ROOT=I:\OSGeo4W64
PROJ_LIB=I:\OSGeo4W64\share\proj
PYTHONHOME=I:\OSGeo4W64\apps\Python36
QGIS_PREFIX_PATH=I:/OSGeo4W64/apps/qgis
QT_PLUGIN_PATH=I:\OSGeo4W64\apps\qgis\qtplugins;I:\OSGeo4W64\apps\qt5\plugins
VSI_CACHE=TRUE
VSI_CACHE_SIZE=1000000
O4W_QT_PREFIX=I:/OSGeo4W64/apps/Qt5
O4W_QT_BINARIES=I:/OSGeo4W64/apps/Qt5/bin
O4W_QT_PLUGINS=I:/OSGeo4W64/apps/Qt5/plugins
O4W_QT_LIBRARIES=I:/OSGeo4W64/apps/Qt5/lib
O4W_QT_TRANSLATIONS=I:/OSGeo4W64/apps/Qt5/translations
O4W_QT_HEADERS=I:/OSGeo4W64/apps/Qt5/include

Hope it will be solved.

2
  • 1
    If you download qgis with the installer, you'll see that they use batch files to set environment variables including pathes and so on. One central variable is OSGEO4W_ROOT, pointing to the base directory. All other pathes are relative to this dir. Concerning python, binarys are in %OSGEO4W_ROOT%\bin, while the main python files are under %OSGEO4W_ROOT%\apps\python36 Commented Jul 20, 2018 at 11:01
  • Are there other variables needed to be set? Please consider giving me an answer instead of comments, thank you. Commented Jul 23, 2018 at 1:31

2 Answers 2

1

my guess is that PYTHONHOME and PYTHONPATH should refer to the desired python inside the QGIS3 folder, something like this

PYTHONHOME = 'C:/Program Files/QGIS 3.2/bin'
PYTHONPATH = 'C:/Program Files/QGIS 3.2/apps/Python36/Lib'
4
  • Well...I realized that something is terribly wrong with the env file... Commented Jul 20, 2018 at 9:16
  • I think the env file is the reason. Would you like to point out what is the right path for these variables? Commented Jul 20, 2018 at 9:21
  • I've edited my answer, use the same paths, they depend on where you have installed your QGIS and what version it is Commented Jul 20, 2018 at 9:29
  • 1
    Thank you! Problem solved. Adding PYTHONPATH really helps. Commented Jul 23, 2018 at 3:47
0

There's a batch file in the qgis package [qgis-3.x.x.tar.bz2] named qgis.bat.tmpl. During installation (postinstall of the package) this file is adapted to the system environment. (by the way, actually, it's left as it is, only renamed to qgis.bat)

This is how the file looks like:

@echo off
call "%~dp0\o4w_env.bat"
call qt5_env.bat
call py3_env.bat
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
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 QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
start "QGIS" /B "%OSGEO4W_ROOT%\bin\qgis-bin.exe" %*

there are some more batch files called, the first on o4w_env.bat calls every bat found under etc/ini, mainly to set things for gdal, proj and others, depending on your installation.

At least, qgis.bat calls qt5_env.bat and py3_env.bat, to set version specific things for qt5 and python3. I think, one will need them both, to have a full functional qgis. Especially the python3 batch file set's the variables, needed for qgis-python support and many plugins a user may installs.

SET PYTHONPATH=
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python36
PATH %OSGEO4W_ROOT%\apps\Python36;%OSGEO4W_ROOT%\apps\Python36\Scripts;%PATH%

Intersting here, that pythonpath is unset, so only pythonhome is used. Normally this is correct as python find modules under %pythonhome%/Lib!

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.