我正在Mac(Sierra)中运行QGIS,但由于此错误而无法加载处理插件:
>>> Couldn't load plugin 'processing'
ImportError: No module named psycopg2
Traceback (most recent call last):
File . "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 308, in loadPlugin
__import__(packageName)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/__init__.py", line 29, in
from processing.tools.general import * # NOQA
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/tools/general.py", line 31, in
from processing.core.Processing import Processing
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/Processing.py", line 42, in
from processing.script.ScriptUtils import ScriptUtils
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/script/ScriptUtils.py", line 30, in
from processing.script.ScriptAlgorithm import ScriptAlgorithm
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/script/ScriptAlgorithm.py", line 33, in
from processing.core.GeoAlgorithm import GeoAlgorithm
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/GeoAlgorithm.py", line 41, in
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, ParameterTable, Parameter
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/parameters.py", line 32, in
from processing.tools.vector import resolveFieldIndex
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/tools/vector.py", line 35, in
import psycopg2
File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named psycopg2
Python version: 2.7.15 (default, Jul 2 2018, 01:42:08) [GCC 4.2.1
Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
QGIS version: 2.18.21 Las Palmas, exported
A从此链接中找到了类似的帖子:
[链接到上一篇文章](ImportError: No module named requests)
当我在python窗口中键入import requests
和import psycopg2
时,我没有收到任何错误:
任何想法为什么会这样? 我将不胜感激。
答案 0 :(得分:1)
尝试安装这些软件包
pip install psycopg2-binary requests
答案 1 :(得分:1)
由于您可以在计算机上安装各种版本的Python,因此要确保pip install psycopg2-binary requests
确实适用于您的QGIS Python环境并不总是那么简单。
您可能希望通过以下操作从QGIS Python console安装软件包:
from pip._internal import main as pipmain
pipmain(['install', 'psycopg2-binary', 'requests'])