I need to start learning Python, and I want to learn with version 3.x. I understand that QGIS–at least some plug-ins–relies on Python and Tcl/Tk, and probably on specific versions. Assuming that QGIS is dependent on Python 2, can anyone tell me how to set up parallel installations of Python 3 and Tcl/Tk such that QGIS will have what it needs and I can use Python 3 for other purposes?
QGIS with Python 3 on Mac – How to Set Up and Use
python 3qgis
Related Solutions
it is a common bug, you can get info here.
for installing qgis for mac os x, you can use Mac OS X installers for QGIS here.
QGIS Standard
Requirements:
GDAL Complete 1.9 framework package
GSL framework
Optional:
GRASS 6.4.2 Python Modules for plugins
i hope it helps you...
So, based on AndreJ comment, I uninstall all PyQt5 related packages with pip3.5
(namely pyqt5
, sip
, qscintilla
and pyqtchart
) and used the official ones from my Ubuntu distribution.
Here is the cmake log which looks fine:
QGIS version: 3.3.0 Master (30300)
Could not find GRASS 7
Found Proj: /usr/local/lib/libproj.so (5.2.0)
Found GEOS: /usr/lib/x86_64-linux-gnu/libgeos_c.so (3.5.0)
Found GDAL: /usr/local/lib/libgdal.so (2.3.1)
Found Expat: /usr/lib/x86_64-linux-gnu/libexpat.so
Found Spatialindex: /usr/lib/x86_64-linux-gnu/libspatialindex.so
Found Qwt: /usr/lib/libqwt-qt5.so (6.1.2)
Found libzip: /usr/lib/x86_64-linux-gnu/libzip.so
Found Sqlite3: /usr/lib/x86_64-linux-gnu/libsqlite3.so
Found PostgreSQL: /usr/lib/x86_64-linux-gnu/libpq.so
Found SpatiaLite: /usr/lib/x86_64-linux-gnu/libspatialite.so
Qt WebKit support DISABLED.
Found Qt version: 5.5.1
Found QScintilla2: /usr/lib/libqt5scintilla2.so (2.9.1)
Found QtKeychain: /usr/lib/x86_64-linux-gnu/libqt5keychain.so
Found QCA: /usr/lib/x86_64-linux-gnu/libqca-qt5.so (2.1.1)
Found QCA OpenSSL plugin
Pedantic compiler settings enabled
Found Python executable: /usr/bin/python3
Found Python version: 3.5.2
Found Python library: /usr/lib/x86_64-linux-gnu/libpython3.5m.so
Found Python site-packages: /usr/lib/python3/dist-packages
Found PyQt5 version: 5.5.1
Found SIP version: 4.17
Found QScintilla2 PyQt module: 2.9.1
Found GSL: -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -lm
Ctest Binary Directory set to: /opt/QGIS/build_master/output/bin
Configuring done
Generating done
(Note: one has to deactivate QtWebKit because it was deprecated since Qt>=5.5)
And here is an error during the compilation:
[ 30%] Generating core/sip_corepart0.cpp, core/sip_corepart1.cpp, core/sip_corepart2.cpp, core/sip_corepart3.cpp
/bin/sh: 1: /usr/bin/sip: not found
python/CMakeFiles/python_module_qgis__core.dir/build.make:515: recipe for target 'python/core/sip_corepart0.cpp' failed
make[2]: *** [python/core/sip_corepart0.cpp] Error 127
make[2]: *** Deleting file 'python/core/sip_corepart0.cpp'
CMakeFiles/Makefile2:4078: recipe for target 'python/CMakeFiles/python_module_qgis__core.dir/all' failed
make[1]: *** [python/CMakeFiles/python_module_qgis__core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
It seems that cmake
can find sip
during the configuration step but the compilation step with make
does not. And I do not have any /usr/bin/sip
on my system even after reinstalling python3-sip
and python3-sip-dev
packages with apt
.
Parenthesis:
If you run into a sipconfig
error or a:
CMake Error at cmake/FindSIP.cmake:54 (MESSAGE):
Could not find SIP
Call Stack (most recent call first):
CMakeLists.txt:753 (FIND_PACKAGE)
after having pip3.5
uninstalled a latest sip
package and if you already have the system sip (python3-sip
python3-sip-dev
) just force the reinstallation of the later:
$ apt-get install python3-sip python3-sip-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-sip is already the newest version (4.17+dfsg-1build1).
python3-sip-dev is already the newest version (4.17+dfsg-1build1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ apt-get install --reinstall python3-sip python3-sip-dev
Then cmake will find it.
Identified problem:
There is two files in the QGIS sources cmake/
folder:
- FindSIP.cmake
- FindSIP.py
the later beeing called by the former.
In the python file, one can read at line:39:
print("sip_bin:%s" % sipcfg.sip_bin)
this line prints:
sip_bin:/usr/bin/sip
But on the system, there is no such sip
file:
ll /usr/bin | grep -i sip
-rwxr-xr-x 1 947 oct 24 2015 dh_sip3*
-rwxr-xr-x 1 868 jan 18 2016 dh_sip*
-rwxr-xr-x 1 59K mai 16 17:00 lsipc*
There is a sip
folder /usr/share
but no executable.
By trying to run sip
:
$ sip -V
The program 'sip' is currently not installed. You can install it by typing:
sudo apt install sip-dev
So.... install it:
$ apt-get install sip-dev
Check it's there:
$ sip -V
4.17
$ ll /usr/bin/ | grep sip
-rwxr-xr-x 1 947 oct 24 2015 dh_sip3*
-rwxr-xr-x 1 868 jan 18 2016 dh_sip*
-rwxr-xr-x 1 357K jan 18 2016 sip*
-rwxr-xr-x 1 59K mai 16 17:00 lsipc*
Yepee, sip
is here now!
And retry the QGIS compilation...:
[...]
[ 99%] Building CXX object python/CMakeFiles/python_module_qgis__gui.dir/gui/sip_guipart0.cpp.o
[ 99%] Building CXX object python/CMakeFiles/python_module_qgis__gui.dir/gui/sip_guipart1.cpp.o
[ 99%] Built target translations
[ 99%] Building CXX object python/CMakeFiles/python_module_qgis__gui.dir/gui/sip_guipart2.cpp.o
[ 99%] Building CXX object python/CMakeFiles/python_module_qgis__gui.dir/gui/sip_guipart3.cpp.o
[100%] Built target staged-plugins-on-build
\o/ YES!
The new issues (2x):
Couldn't load PyQGIS.
Python support will be disabled.
Traceback (most recent call last):
File "", line 1, in
File "/opt/QGIS/build_master/output/python/qgis/core/__init__.py", line 27, in
from qgis._core import *
ImportError: No module named 'PyQt5.QtSql'
Python version:
3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609]
QGIS version:
3.3.0-Master 'Master', a82de83
To fix this one, one has to install pyqt5.qtsql
manually (it does not seem to come along python3-pyqt5
):
$ apt-get install python3-pyqt5.qtsql
(...) Same thing for 'PyQt5.QtSvg':
$ apt-get install python3-pyqt5.qtsvg
Then, QGIS finally starts normally with a nice Python console:
The two last issues were clearly due to a lack in the dependencies installation from my side.
Best Answer
pyrogerg, you can have several versions of Python on your Mac (Mac OS X's, Macports, python.org framework, etc.) and it will not mess with QGIS, or any of the other versions of Python (older, but still relevant, similar question). You can also switch between them, or call a specific-version interpreter in Terminal (e.g. /usr/bin/python2.5), and some folks have made it easier on themselves. In fact, your Mac has several versions of Python already installed. Check /usr/bin. There is 2.5, 2.6, and 2.7 installed with Lion.
Concerning whether a Python 3 install will affect QGIS... basically no. If you are using the KyngChaos.com QGIS installs, they are compiled against the most current version of Python on the stock Mac OS X version they are built for (2.7 for Lion). A Python 3 (or 2.5) interpreter will not be used for the QGIS's internal Python environment, only the one it was compiled against.
Modules installed for the Python-specific version (here for stock Lion)...
will be available in QGIS, but plugin-local packages or modules of the same name will be loaded before them, as the plugin location paths (e.g.
~/.qgis/python/plugins/
) precede site-packages on sys.path.Things change if you want to compile QGIS yourself (to use latest master branch from github.com repository). Then you need to be specific when choosing the version of Python for which to build the app. Python 3 is not recommended at this time. See Mac section #5 of INSTALL.
Concerning the GUI toolkit used when building PyQGIS plugins, it is PyQt (not Tcl/Tk), which is a Python binding for Nokia's Qt C++ GUI toolkit, which is what QGIS is built with. The KyngChaos.com QGIS.apps are bundled with most of the Qt frameworks they were compiled against. See:
This means that you can also have different versions of Qt installed on your Mac as well, without affecting QGIS's build. Rarely there are issues with plugins 'seeing' two Qt installs and not knowing which to use, but it doesn't mean the plugin will crash.
If you are curious about building the current master branch of QGIS, and have a build environment setup as per INSTALL, try out this no frills script for automating the build.
Have fun learning Python. Certainly nothing wrong with learning 2.x and then move to 3.x. There are many, many apps, modules and plugins out there written with 2.x. If you are looking for a good IDE to learn Python, especially PyQt, try Eric4 or 5. It is actually built from PyQt as well.