3liz / py-qgis-server

QGIS embbeded WMS/WFS/WCS asynchronous scalable http server
https://docs.3liz.org/py-qgis-server
Mozilla Public License 2.0
68 stars 16 forks source link

ModuleNotFoundError: No module named 'qgis' #32

Closed yamamoto-ryuzo closed 2 years ago

yamamoto-ryuzo commented 2 years ago

Is this error due to a problem with my installation?


Traceback (most recent call last): File "/usr/local/bin/qgisserver", line 33, in sys.exit(load_entry_point('py-qgis-server==1.7.12', 'console_scripts', 'qgisserver')()) File "/usr/local/bin/qgisserver", line 25, in importlib_load_entry_point return next(matches).load() File "/usr/local/lib/python3.9/importlib/metadata.py", line 77, in load module = import_module(match.group('module')) File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/usr/local/lib/python3.9/site-packages/pyqgisserver/server.py", line 22, in from .runtime import run_server File "/usr/local/lib/python3.9/site-packages/pyqgisserver/runtime.py", line 36, in from .qgspool import create_poolserver File "/usr/local/lib/python3.9/site-packages/pyqgisserver/qgspool.py", line 33, in from .qgsworker import QgsRequestHandler File "/usr/local/lib/python3.9/site-packages/pyqgisserver/qgsworker.py", line 23, in from qgis.PyQt.QtCore import Qt, QBuffer, QIODevice, QByteArray ModuleNotFoundError: No module named 'qgis'

yamamoto-ryuzo commented 2 years ago

I installed the following onUbuntu 18.04.6 LTS

sudo su

不要なものを削除

sudo apt autoremove

システムを最新に

apt -y upgrade

pipのインストール

apt update apt -y uninstall python3-pip apt -y install python3-pip pip install --upgrade pip

zmq

pip uninstall -y pyzmq pip install --no-cache-dir pyzmq

libzmq

sudo apt-get install libzmq3-dev apt -y install libzmq5

py-qgis-serverのインストール

再インストールの場合は一度アンインストール

pip uninstall -y py-qgis-server pip install --no-cache-dir py-qgis-server

yamamoto-ryuzo commented 2 years ago

Try the following

https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/intro.html#id12

1.4.3. Running Custom Applications You need to tell your system where to search for QGIS libraries and appropriate Python modules if they are not in a well-known location - otherwise Python will complain:

import qgis.core ImportError: No module named qgis.core This can be fixed by setting the PYTHONPATH environment variable. In the following commands, should be replaced with your actual QGIS installation path:

on Linux: export PYTHONPATH=//share/qgis/python

on Windows: set PYTHONPATH=c:\\python

on macOS: export PYTHONPATH=//Contents/Resources/python

Now, the path to the PyQGIS modules is known, but they depend on the qgis_core and qgis_gui libraries (the Python modules serve only as wrappers). The path to these libraries may be unknown to the operating system, and then you will get an import error again (the message might vary depending on the system):

import qgis.core ImportError: libqgis_core.so.3.2.0: cannot open shared object file: No such file or directory Fix this by adding the directories where the QGIS libraries reside to the search path of the dynamic linker:

on Linux: export LD_LIBRARY_PATH=//lib

on Windows: set PATH=C:\\bin;C:\\apps\\bin;%PATH% where should be replaced with the type of release you are targeting (eg, qgis-ltr, qgis, qgis-dev)

These commands can be put into a bootstrap script that will take care of the startup. When deploying custom applications using PyQGIS, there are usually two possibilities:

require the user to install QGIS prior to installing your application. The application installer should look for default locations of QGIS libraries and allow the user to set the path if not found. This approach has the advantage of being simpler, however it requires the user to do more steps.

package QGIS together with your application. Releasing the application may be more challenging and the package will be larger, but the user will be saved from the burden of downloading and installing additional pieces of software.

The two deployment models can be mixed. You can provide a standalone applications on Windows and macOS, but for Linux leave the installation of GIS up to the user and his package manager.

dmarteau commented 2 years ago

This is clearly a problem with your installation.

You can refer to how we install qgis in the docker image on the (qgis base image)[https://github.com/3liz/docker-qgis-platform/blob/master/Dockerfile.ubuntu]

Do not rely on the default Qgis packages but rather those provided at https://qgis.org/

dmarteau commented 2 years ago

Note that latest release version of Qgis (3.22) will not work on ubuntu 18.04 because of obsolete version of dependencies (i.e gdal). You should consider using the docker images.

yamamoto-ryuzo commented 2 years ago

Thank you very much. It seems to be difficult for my ability to explain clearly to many people. This introduction of speedup is limited to multi-threading of GIMAPSERVER. In the future, I will try to make a page to introduce QGIS project settings that can speed up QGIMAPSERVER, which is the bottleneck of speedup.

dmarteau commented 2 years ago

Closing stalled issue.